开发者

NServicebus added to legacy windows service

I have a simple class which sets up NserviceBus for a legacy windows service. This configuration is called when the service starts up. When I run the application as a console app the configuration in the App.config is picked up, however when running the application as a windows service the App.config configuration isn't picked up. 开发者_JAVA百科Is there any way I can specify the app config location? (as I have done with the log4net.config).

namespace MossSapUploadInterface
{
    public static class BootStrapper
    {
        public static void Init()
        {
            var config = AppDomain.CurrentDomain.BaseDirectory + "log4net.config";
            XmlConfigurator.Configure(new FileInfo(config));
            var log = LogManager.GetLogger(typeof(BootStrapper));
            ObjectFactory.Initialize(x => x.AddRegistry<MessageServiceRegistry>());
            ObjectFactory.Configure(x => x.For<ILog>().TheDefault.Is.Object(log));


            var bus = Configure.With()
                .StructureMapBuilder(ObjectFactory.Container)
                .MsmqTransport()
                .IsTransactional(true)
                .UnicastBus()
                .ImpersonateSender(false)
                .XmlSerializer()
                .CreateBus()
                .Start();
            SetLoggingLibrary.Log4Net();
        }
    }
}


One way to solve this would be to implement your own custom config source:

http://sourceforge.net/apps/mediawiki/nservicebus/index.php?title=Overriding_Configuration


I can confirm I was wrong. The configuration is picked up from the App.config. As verified by the following log:

var destinationQueue = Configure.ConfigurationSource.GetConfiguration<UnicastBusConfig>().MessageEndpointMappings[0].Endpoint;
log.Info("Endpoint Mapped to: " + destinationQueue);

Seems the structuremap config does look in current domain directory for the configuration, as opposed to my first thoughts of the default services directory: "c:\Windows\system32..."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜