Beispiel #1
0
        public AppServerHost(string instanceName, IReadOnlyList <IAppServerComponent> components)
        {
            this._state = AppServerHostState.Initializing;

            this._instanceName = instanceName;

            this._container = new WindsorContainer()
                              .Install(new AppServerInstaller(this));

            this._logger = this._container.Resolve <ILogger>();

            this._logger.Info("AppServer: Server Host is initializing ...");
            this._logger.Info("AppServer: The DI-Container has been initialized.");
            this._logger.Info("AppServer: The Logger has been initialized.");

            this._serverContext = this._container.Resolve <IAppServerContext>();

            this._logger.Info("AppServer: The Server Context has been initialized.");

            this._components = new List <IAppServerComponent>();
            if (components != null && components.Count > 0)
            {
                this._components.AddRange(components);
                foreach (var component in this._components)
                {
                    component.Install(this._container, this._serverContext);
                }
            }
            this._logger.Info("AppServer: The Server Components has been installed.");

            this._state = AppServerHostState.Initialized;

            this._logger.Info("AppServer: Server Host has been initialized successfully.");
        }
Beispiel #2
0
        protected virtual void Dispose(bool disposing)
        {
            if (this._state != AppServerHostState.Disposed && this._state != AppServerHostState.Disposing)
            {
                this._state = AppServerHostState.Disposing;

                if (disposing)
                {
                    this._logger.Info("AppServere: Stoping ...");

                    // TODO: dispose managed state (managed objects).
                    if (this._components != null)
                    {
                        foreach (var component in this._components)
                        {
                            component.Deactivate();
                        }
                        this._logger.Info("AppServer: The Server Components has been deactivating");

                        foreach (var component in this._components)
                        {
                            component.Uninstall(this._container, this._serverContext);
                        }

                        this._logger.Info("AppServer: The Server Components has been uninstalling");
                    }

                    if (this._container != null)
                    {
                        this._logger.Info("AppServer: The DI-Container has been closing");
                        this._logger.Info("AppServer: The Server Host has been stoping");
                        this._logger = null;
                        this._container.Dispose();
                        this._container = null;
                    }
                }

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.

                this._state = AppServerHostState.Disposed;
            }
        }