2016-11-15 9 views
0

NServiceBus.vostを使用してNServiceBus v6を使用しています。私はmessageSessionオブジェクトを解決できません。私は何が欠けていますか?NServiceBus - 6.xでCastleWindsorでIMessageSessionを解決できません。

var container2 = new WindsorContainer(); 
     Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); 
     log4net.Config.XmlConfigurator.Configure(new FileInfo("logging.config")); 
     LogManager.Use<Log4NetFactory>(); 

     endpointConfiguration.DefineEndpointName("Strategy.Service"); 
     endpointConfiguration.UseSerialization<JsonSerializer>(); 
     endpointConfiguration.UsePersistence<NHibernatePersistence>(); 
     endpointConfiguration.UseTransport<SqlServerTransport>(); 
     endpointConfiguration.Conventions() 
      .DefiningCommandsAs(x => x.Namespace != null && x.Namespace.Contains("Commands")) 
      .DefiningEventsAs(x => x.Namespace != null && x.Namespace.Contains("Events")); 
     endpointConfiguration.UseContainer<WindsorBuilder>(
      customizations: customizations => 
      { 
       customizations.ExistingContainer(container2); 
      }); 
     endpointConfiguration.SendFailedMessagesTo("error"); 
     endpointConfiguration.AuditProcessedMessagesTo("audit"); 
     endpointConfiguration.DefineCriticalErrorAction(onCriticalError: async context => 
     { 
      _logger.Fatal($"CRITICAL: {context.Error}", context.Exception); 
      await context.Stop() 
       .ConfigureAwait(false); 
      var output = 
       $"NServiceBus critical error: {Environment.NewLine}{context.Error}{Environment.NewLine}Shutting Down."; 
      Environment.FailFast(output, context.Exception); 
     }); 
     var msgSessions = container2.Resolve<IMessageSession>(); // Cannot resolve IMessageSession. 

答えて

3

IMessageSessionはNServiceBusによってコンテナに登録されていません。

var endpointInstance = await Endpoint.Start(endpointConfiguration); 
IMessageSession messageSession = endpointInstance as IMessageSession; 

IMessageSessionがNServiceBusによって容器に注入されていない理由の詳細については、https://docs.particular.net/nservicebus/upgrades/5to6/moving-away-from-ibus#dependency-injectionを参照してください:あなたはエンドポイントを開始するときは、IMessageSessionへの参照を取得します。

+0

私はNServiceBus.Hostを使用しています - 私はEndPointConfigurationインスタンスを取得するので、エンドポイントの起動について心配する必要はありません。私は、IMessageSessionのインスタンスを取得するためにIWantToRunWhenEndpointStartsAndStopsを実装するための粗末な方法がありますが、正しいアプローチがあるかどうかはわかりません – Bitmask

+1

私が別の質問に与えたこの回答は役に立ちます:http://stackoverflow.com/a/40348435/1322687 –

関連する問題