public static void Unload(AppDomain domain) { var assembly = domain.GetAssemblies()[1]; var filePath = assembly.CodeBase; Commands.Where(c => assembly == c.GetType().Assembly).ToList().ForEach(c => Commands.Remove(c)); EventConsumers.Where(c => assembly == c.GetType().Assembly).ToList().ForEach(c => EventConsumers.Remove(c)); EventSources.Where(c => assembly == c.GetType().Assembly).ToList().ForEach(c => EventSources.Remove(c)); Services.Where(c => assembly == c.GetType().Assembly).ToList().ForEach(c => { c.Stop(); Services.Remove(c); }); Bindings.Where(c => assembly == c.GetType().Assembly).ToList().ForEach(c => Bindings.Remove(c)); Domains.Remove(domain); AppDomain.Unload(domain); GC.Collect(); // collects all unused memory GC.WaitForPendingFinalizers(); // wait until GC has finished its work GC.Collect(); //File.Delete(filePath); }
private static void LoadConsumers() { EventConsumers.AddRange(GetClassesOfType <IEventConsumer>()); }