本文介绍了NServicebus 中的 RaventBootstrapper 配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使 Andreas Öhlund 提供的以下 NServiceBus Pluralsight 培训代码示例发挥作用.
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);
}
}
有多个关于过时代码的编译错误,我能够更正其中的大部分错误,但在 Configure.Instance.Builder.Build 上得到了库存......这是我目前所拥有的:>
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));
}
- Builder.Build 的新等价物是什么?
- 其他的好看吗?
- 很高兴知道我可以在 NserviceBus 文档中具体在哪里找到答案.
推荐答案
Configure.Component 有一个重载,它接受一个 Func
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));
这篇关于NServicebus 中的 RaventBootstrapper 配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!