/// <summary> /// Initializes the <see cref="This"/> class. /// </summary> static This() { parentContainer = new ObservableServiceContainer(); childContainer = new ObservableServiceContainer(parentContainer); AddDefaultServices(); WireEvents(); // Child service container events. AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnCurrentDomainUnhandledException); AppDomain.CurrentDomain.ProcessExit += delegate { DisposeClass(); }; }
/// <summary> /// Disposes all disposable members of the class (among which, the service containers). /// </summary> /// <remarks> /// Disposing the service containers automatically disposes all the disposable service /// instances they may host. /// </remarks> private static void DisposeClass() { disposed = true; // Remark: calling ServiceContainer.Dispose() disposes // all disposable services that are contained in the container. if (childContainer != null) { childContainer.Dispose(); childContainer = null; } if (parentContainer != null) { parentContainer.Dispose(); parentContainer = null; } }