/// <summary> /// This method is called for every component that is created via Castle/Windsor. /// </summary> /// <remarks> /// Currently the only instances we're interested in are those bearing the IBackgroundThread interface, /// because we need to shut them down when the application terminates. The reason that we /// need to record the stoppable instances, rather than just doing a ResovleAll, is that /// ResolveAll can actually create instances of components, whereas we really only want to /// get those components which have been created elsewhere. /// </remarks> private static void Kernel_ComponentCreated(ComponentModel model, object instance) { if (instance is IHaveBackgroundThread) { StoppableInstances.Add((instance as IHaveBackgroundThread)); } }
/// <summary> /// Call stop on all IoC components that have the IBackgrounfThread interface. /// </summary> private static void ShutdownBackgroundThreads() { if (StoppableInstances.Count() == 0) { return; } var msg = StoppableInstances.Select(s => s.GetType().ToString()).Aggregate((c, a) => a + ", " + c); Logger.InfoFormat("IoCSetup::ShutdownStoppables - Stopping {0}.", msg); StoppableInstances.ForEach(s => StopIfNotCurrent(s)); }