问题
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));
}
- What is a new equivalent of Builder.Build?
- Does the rest look good?
- 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