0

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-

Dave Nichol
  • 181
  • 3
  • 8
  • 1
    I think you many 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. – Adam Fyles Apr 12 '11 at 12:34

1 Answers1

2

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)

Adam Fyles
  • 6,030
  • 1
  • 23
  • 29