NServiceBus property not injecting
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 vo开发者_C百科id 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-
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)
精彩评论