何在TopShelf中将HostControl实例传递给自定义主

何在TopShelf中将HostControl实例传递给自定义主

本文介绍了如何在TopShelf中将HostControl实例传递给自定义主机服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此,但没有迹象表明我如何获得 HostControl 的实例。我的TopShelf主程序如下所示:

This question has been asked elsewhere on SO, but there is no indication of how I get an instance of a HostControl as the post suggests. My TopShelf main program looks like this:

    public static void Main()
    {
        HostFactory.Run(CreateHost);
    }

    private static void CreateHost(HostConfigurator x)
    {
        x.UseLog4Net();

        x.Service<EventBroker>(s =>
        {
            s.ConstructUsing(name => new EventBroker());
            s.WhenStarted(tc => tc.Start());
            s.WhenStopped(tc => tc.Stop());
        });

        x.StartAutomatically();

        x.RunAsNetworkService();
    }

有任何建议吗?

推荐答案

开始更改后,将HostControl传递给它

Change WhenStarted to have HostControl passed to it like this

   s.WhenStarted((tc, hostControl) => tc.Start(hostControl));

此处的每个TopShelf文档

Per TopShelf documentation herehttp://topshelf.readthedocs.org/en/latest/configuration/config_api.html

这篇关于如何在TopShelf中将HostControl实例传递给自定义主机服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 23:43