与ninject的nservicebus saga属性注入

时间:2012-04-15 01:00:44

标签: ninject nservicebus cqrs

我在配置NSB时使用ninject。以下是我注册的方式:

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
}

我需要传奇中的IAggregateRootFactory。

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

    // removed implementation
}

saga已成功启动,并且命令是处理程序被调用。但是IAggregateRootFactory属性注入不起作用。工厂始终为空。我接错了吗?

1 个答案:

答案 0 :(得分:1)

我不太清楚为什么你的saga需要有RegistrationFactory / IAggregateRootFactory,但它可能不是一个好主意。