RaventBootstrapper configuration in NServicebus

不想你离开。 提交于 2020-01-06 13:55:24

问题


I'm trying to make the following NServiceBus Pluralsight training code sample by Andreas Öhlund to work.

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);

    }
}

There were multiple compile errors about obsolete code and I was able to correct most of them but got stock on Configure.Instance.Builder.Build... Here's what I have so far:

 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. What is a new equivalent of Builder.Build?
  2. Does the rest look good?
  3. Would be nice to know where specifically I could find an answer to this in NserviceBus documentation.

回答1:


There is an overload to Configure.Component that accepts a Func<IBuilder,TComponent>

Using this you can change your code to:

 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));



回答2:


Mauro Servienti from Particular Software just posted a webinar that you may find helpful. https://particular-1.wistia.com/medias/q8tdr6mnzz



来源:https://stackoverflow.com/questions/26365296/raventbootstrapper-configuration-in-nservicebus

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!