// ReSharper disable UnusedMember.Local void InitializeAndCreateHostedService <T>(Bootstrapper <T> bootstrapper) // ReSharper restore UnusedMember.Local where T : class { _log.DebugFormat("[{0}] Creating service type: {1}", _serviceName, typeof(T).ToShortTypeName()); _fiber = new PoolFiber(); _channel = HostChannelFactory.CreateShelfHost(_serviceName, AddEventForwarders); _controllerChannel.Send(new ShelfCreated(_serviceName, _channel.Address, _channel.PipeName)); _host = HostFactory.New(x => { x.SetServiceName(_serviceName); x.UseBuilder(description => new ShelfBuilder(description, _channel)); x.Service <T>(s => { var serviceConfigurator = new ServiceConfiguratorImpl <T>(s); bootstrapper.InitializeHostedService(serviceConfigurator); s.SetServiceName(_serviceName); }); }); _host.Run(); }
void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { if (_channel != null) { _channel.Dispose(); _channel = null; } if (_controllerChannel != null) { _controllerChannel.Dispose(); _controllerChannel = null; } Logger.Shutdown(); } _disposed = true; }
void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { if (_hostChannel != null) { _hostChannel.Dispose(); _hostChannel = null; } if (_channel != null) { _channel.Dispose(); _channel = null; } _domain = null; } _disposed = true; }
void CreateShelfInstance(Type bootstrapperType) { _log.DebugFormat("[{0}] Creating Host Channel", _serviceName); _hostChannel = HostChannelFactory.CreateShelfControllerHost(_controllerChannel, _serviceName); _log.InfoFormat("[{0}] Created Host Channel: {1}({2})", _serviceName, _hostChannel.Address, _hostChannel.PipeName); _log.DebugFormat("Creating Shelf Instance: " + _serviceName); Type shelfType = typeof(Shelf); _objectHandle = _domain.CreateInstance(shelfType.Assembly.GetName().FullName, shelfType.FullName, true, 0, null, new object[] { bootstrapperType, _hostChannel.Address, _hostChannel.PipeName }, null, null, null); }
void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { if (_hostChannel != null) { _hostChannel.Dispose(); _hostChannel = null; } if (_channel != null) { _channel.Dispose(); _channel = null; } try { _log.DebugFormat("[{0}] Unloading AppDomain", _serviceName); _log.InfoFormat("[{0}] AppDomain Unloaded", _serviceName); } catch (Exception) { _log.DebugFormat("[{0}] AppDomain was already unloaded", _serviceName); } finally { _domain = null; } } _disposed = true; }