NServiceBus 属性未注入
我正在运行 NServiceBus 2.0 并尝试创建一个服务来接收转发的消息并将它们放入(RavenDB)数据库中。我承认我对 NServiceBus 如何与 IoC 容器一起工作并没有牢固的掌握(我以前也没有使用过 Spring),所以我可能做错了一些事情。
在我的 IWantToRunOnStartup 类中,我在调用 Store.Initialize() 时遇到空引用异常。我是否正确连接了这个单例?我需要在配置文件中做些什么吗?
这是代码:
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization
{
private IMessageRepository _store;
public void Init()
{
_store = new RavenMessageRepository();
Configure.With()
.DefaultBuilder()
.XmlSerializer()
.UnicastBus();
Configure.Instance.Configurer.RegisterSingleton<IMessageRepository>(_store);
}
}
public class StartupConfig : IWantToRunAtStartup
{
public IMessageRepository Store;
public void Run()
{
Store.Initialize();
}
public void Stop()
{
}
}
谢谢-
I'm running NServiceBus 2.0 and trying to create a service to receive forwarded messages and drop them in a (RavenDB) database. I admit I don't have a firm grasp on how NServiceBus works with IoC containers (nor have I used Spring before), so I may be doing something wrong.
In my IWantToRunOnStartup class, I'm getting a null reference exception where I call Store.Initialize(). Am I hooking up this singleton correctly? Is there anything I need to do in the config files?
Here is the code:
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization
{
private IMessageRepository _store;
public void Init()
{
_store = new RavenMessageRepository();
Configure.With()
.DefaultBuilder()
.XmlSerializer()
.UnicastBus();
Configure.Instance.Configurer.RegisterSingleton<IMessageRepository>(_store);
}
}
public class StartupConfig : IWantToRunAtStartup
{
public IMessageRepository Store;
public void Run()
{
Store.Initialize();
}
public void Stop()
{
}
}
Thanks-
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将 Store 成员更改为具有 get/set 的属性。我还没有确认这一点,但是容器可能正在寻找一个设置器并且找不到它(从评论中复制,以便其他人将其视为已回答)
You need to change your Store member to a property with a get/set. I have not confirmed this, but the container is probably looking for a setter and can't find it(copied from comment so others see it as answered)