2013-01-08 96 views
4

我在評論MassTransit Distributed Application Framework for .NET。根據網站MassTransit has been built from the beginning with the concept of an IoC container being involved,併爲少數「主流」IoC容器提供支持庫。目前有NuGet軟件包可用於Autofac,StructureMap,Castle Windsor,Ninject & Unity。MassTransit和簡單噴油器

我選擇了Simple Injector作爲我選擇的IoC容器for performance reasons,但我無法找到將簡單噴射器支持到MassTransit的集成庫。

有沒有人試過這個,得到它的工作,並有一些代碼可以讓我開始?

+0

有用於簡單的噴油器,我知道沒有MassTransit集成庫。 – Steven

+0

有一個NuGet包在https://www.nuget.org/packages/MassTransit.SimpleInjector/ – sduplooy

回答

6

我不熟悉MassTransit,但看着the configuration examples for the other containers後,這是我想出了:

public static void main(string[] args) 
{ 
    var container = new Container(); 

    var consumers = container.GetTypesToRegister(typeof(IConsumer), 
     applicationAssemblies); 

    foreach (Type consumer in consumers) 
     container.Register(consumer); 

    IServiceBus bus = ServiceBusFactory.New(sbc => { 
     //other configuration options 

     sbc.Subscribe(subs => { 
      foreach (var consumer in consumers) 
       subs.Consumer(consumer); 
     }); 
    }); 

    container.RegisterSingle<IServiceBus>(bus); 

    container.Verify(); 
} 
+0

謝謝史蒂文。目前,我已經使用RegisterManyForOpenGeneric \ RegisterAll和GetAllInstances等實現了SimpleInjector的本地發佈/訂閱框架。我將在稍後的項目中審查消息分發。 – qujck

相關問題