0
votes

I am using ninject when configuring NSB. Here is how I register:

public class EndpointConfig : IConfigureThisEndpoint, AsA_Publisher, IWantCustomInitialization
{
    #region Implementation of IWantCustomInitialization

    public void Init()
    {
        var kernel = new StandardKernel();

        Configure.With().NinjectBuilder(kernel);

        kernel.Load(new BackendModule());
    }

    #endregion
}
public class BackendModule : NinjectModule
{
    #region Overrides of NinjectModule

    /// <summary>
    /// Loads the module into the kernel.
    /// </summary>
    public override void Load()
    {
        Bind<IEventBus>().To<NsbBus>();
        Bind<IRecordStorageConfig>().To<RegistrationEventStorageConfig>();
        Bind<IRecordStorage>().To<RegistrationRecordStorage>();
        Bind<IRecordStorageFactory>().To<RegistrationRecordStorageFactory>();
        Bind<IAggregateRootFactory>().To<RegistrationFactory>();
    }

    #endregion
}

I need the IAggregateRootFactory in the saga.

public class RegistrationSaga : Saga<RegistrationSagaData>,
                                IAmStartedByMessages<StartRegistration>,
                                IHandleMessages<CreateRegistration>,
                                IHandleMessages<ValidateRegistration>,
                                IHandleMessages<CancelRegistration>
{
    public RegistrationFactory Factory { get; set; }

    // removed implementation
}

The saga is started successfully and the commands are handlers are invoked. But the IAggregateRootFactory property injection is not working. The Factory is always null. Am I wiring this wrong?

1
NsbBus is just a wrapper and looks like this: public class NsbBus : IEventBus { private readonly IBus m_nsb; public NsbBus(IBus nsb) { m_nsb = nsb; } #region Implementation of IEventBus public void Publish<T>(T @event) where T : class, IEvent<IIdentity> { m_nsb.Publish(@event); } public void PublishAll<T>(IEnumerable<T> events) where T : class, IEvent<IIdentity> { foreach (var @event in events) m_nsb.Publish(@event); } #endregion } - kind_robot
I changed to Autofac and registered that factory as well but, factory is still null in the saga... - kind_robot

1 Answers

1
votes

I'm not quite sure why your saga needs to have RegistrationFactory/IAggregateRootFactory in it, but it probably isn't a good idea.