NServicebus中的RaventBootstrapper配置

时间:2014-10-14 16:06:34

标签: c# nservicebus

我正在努力使AndreasÖhlund的以下NServiceBus Pluralsight培训代码示例工作。

public class RavenBootstrapper : INeedInitialization
{
    public void Init()
    {
        Configure.Instance.Configurer.ConfigureComponent<IDocumentStore>(
            () =>
            {
                var store = new DocumentStore
                            {
                                Url = "http://localhost:8080"
                            };

                store.Initialize();
                store.JsonRequestFactory.DisableRequestCompression = true;
                return store;
            }
            , DependencyLifecycle.SingleInstance);

        Configure.Instance.Configurer.ConfigureComponent<IDocumentSession>(
            () =>
            {

                return Configure.Instance.Builder.Build<IDocumentStore>()
                    .OpenSession();
            },
            DependencyLifecycle.InstancePerUnitOfWork);

        Configure.Instance.Configurer.ConfigureComponent<RavenUnitOfWork>(DependencyLifecycle.InstancePerUnitOfWork);

    }
}

关于过时的代码存在多个编译错误,我能够纠正其中的大部分,但是在 Configure.Instance.Builder.Build 上获得了库存...这是我到目前为止所拥有的:

 public class RavenBootstrapper : INeedInitialization
{

        configuration.RegisterComponents(c => c.ConfigureComponent<IDocumentStore>(
           () =>
           {
             var  store = new DocumentStore
                         {
                             Url = "http://localhost:8080"
                         };

               store.Initialize();
               store.JsonRequestFactory.DisableRequestCompression = true;
               return store;
           }
           , DependencyLifecycle.SingleInstance));


        configuration.RegisterComponents(c => 
            c.ConfigureComponent(builder => builder.Build<IDocumentStore>().OpenSession(),DependencyLifecycle.InstancePerUnitOfWork));

        configuration.RegisterComponents(c => c.ConfigureComponent<RavenUnitOfWork>(DependencyLifecycle.InstancePerUnitOfWork));
}
  1. 什么是Builder.Build的新等价物?
  2. 其余的看起来不错吗?
  3. 很高兴知道在NserviceBus文档中我能找到答案。

2 个答案:

答案 0 :(得分:2)

Configure.Component有一个接受Func<IBuilder,TComponent>

的重载

使用此功能,您可以将代码更改为:

 configuration.RegisterComponents(c => c.ConfigureComponent<IDocumentStore>(
           () =>
           {
               var store = new DocumentStore
                           {
                               Url = "http://localhost:8080"
                           };

               store.Initialize();
               store.JsonRequestFactory.DisableRequestCompression = true;
               return store;
           }
           , DependencyLifecycle.SingleInstance));

        configuration.RegisterComponents(c => c.ConfigureComponent<IDocumentSession>(
            builder =>
            {

                return builder.Build<IDocumentStore>()
                    .OpenSession();
            },
            DependencyLifecycle.InstancePerUnitOfWork));

答案 1 :(得分:0)

来自Particular Software的Mauro Servienti刚刚发布了一个网络研讨会,您可能会发现它很有帮助。 https://particular-1.wistia.com/medias/q8tdr6mnzz