Obviously, when the application pool is processed, the assemblies are freed, which leads to the fact that Unity cannot find the declared classes in it.
I managed to solve this effect by specifically downloading builds for Unity. Thus, they remain in memory even when the application pool is being processed.
public static void Configure(Func<IAutoRegistration,IAutoRegistration> configuration) { // Create new UnityContainer with auto registration container = new UnityContainer(); var autoRegistration = container.ConfigureAutoRegistration(); // Load assemblies var path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "bin"); foreach (string dll in Directory.GetFiles(path, "*.dll", SearchOption.AllDirectories)) { autoRegistration.LoadAssemblyFrom(dll); } // Apply configuration configuration(autoRegistration).ApplyAutoRegistration(); }
And to answer my questions:
What's going on here? Why does Unity forget about all my classes?
When the application pool is processed, assemblies can be freed from memory. When they are needed again, they reboot. However, since they seem to come from different files, Unity cannot know that they are in fact the same assemblies as before, and therefore cannot find the original class definitions.
And is there an event that I can subscribe to that lets me know when the pool was redesigned?
There seems to be no such thing.
source share