2017-09-04 5 views
1

NServiceBus.AutofacパッケージでNServiceBus 6を使用しています。NServiceBus Autofac子スコープ

私は子AutofacコンテナでNServiceBusを設定していたとき、私は(オーバーライドAttachToComponentRegistrationメソッドを介して)カスタムAutofacモジュールに登録されているいくつかの共通のインタフェースILoggerです

を持って、残念ながら、すべての私のメッセージハンドラは解決できませんでしたILoggerの依存関係。

 endpointConfiguration.UseContainer<AutofacBuilder>(
     customizations: customizations => 
     { 
      var childContainer = _container.BeginLifetimeScope(); 
      customizations.ExistingLifetimeScope(childContainer); 
     }); 

NServceBusが(子スコープ=のみルートコンテナなし)、次のように構成されている場合しかし、すべてが完璧に動作します:

 endpointConfiguration.UseContainer<AutofacBuilder>(
     customizations: customizations => 
     { 
      customizations.ExistingLifetimeScope(_container); 
     }); 

んNServiceBusが正しく子Autofacスコープをサポートしていますか?

+0

を追加しました[サンプルプロジェクト](https://gitlab.com/alex_sk_/nsb_logging/blob/master:

クイックフィックスは、新しい生涯スコープを作成するたびにモジュールを再登録することです/NSB_Logging/Program.cs#L35) –

答えて

1

これは、Autofacが子どもの生涯にわたるスコープでモジュールを扱う方法に関連しています。子スコープ内のモジュールは期待どおりに処理されないようです。 Github issue here

endpointConfiguration.UseContainer<AutofacBuilder>(
customizations: customizations => 
{ 
    var childScope = _container.BeginLifetimeScope(b => b.RegisterModule<NLogModule>()); 

    customizations.ExistingLifetimeScope(childScope); // THIS LINE DOESN'T WORK PROPERLY 
    //customizations.ExistingLifetimeScope(_container); // THIS LINE WORKS 
}); 
関連する問題