コード例 #1
0
ファイル: Shelf.cs プロジェクト: xiaopohou/Topshelf
        // 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();
        }
コード例 #2
0
ファイル: ShelfReference.cs プロジェクト: haf/Topshelf
        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);
        }