2

我下面的传奇没有处理 ValidateRegistration 和 ValidateRegistration 命令。我看到“找不到消息类型 Registrations.Messages.ValidateRegistration with id ...的传奇”消息。

我查找 saga 的配置不正确吗?请帮忙!

谢谢

PS:我在注册过程中使用的是通用主机,并且我使用的是 NServiceBus.Lite 配置文件。

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

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

        //Configure.Instance.Configurer.ConfigureProperty<RegistrationSaga>(x => x.Factory, kernel.Get<IAggregateRootFactory>());
        Configure.With().NinjectBuilder(kernel);
    }

    #endregion
}

public class RegistrationSagaData : IContainSagaData
{
    #region Implementation of ISagaEntity

    public virtual Guid Id { get; set; }
    public virtual string Originator { get; set; }
    public virtual string OriginalMessageId { get; set; }

    public virtual RegistrationID RegistrationID { get; set; }
    public virtual bool IsValidated { get; set; }
    public virtual string RegistrationType { get; set; }

    #endregion
}

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

    public override void ConfigureHowToFindSaga()
    {
        ConfigureMapping<StartRegistration>(data => data.RegistrationID, registration => registration.ID);
        ConfigureMapping<ValidateRegistration>(data => data.RegistrationID, registration => registration.ID);
        ConfigureMapping<CancelRegistration>(data => data.RegistrationID, registration => registration.ID);
    }

    #region Implementation of IMessageHandler<StartRegistration>

    public void Handle(StartRegistration message)
    {
        Data.IsValidated = false;
        Data.RegistrationType = message.RegistrationType;

        Bus.SendLocal(new CreateRegistration
        {
            RegistrationType = message.RegistrationType,
            ID = message.ID
        });

        Console.WriteLine("======> handled StartRegistration");
    }

    #endregion

    #region Implementation of IMessageHandler<ValidateRegistration>

    public void Handle(ValidateRegistration message)
    {
        MarkAsComplete();

        Console.WriteLine("======> handled ValidateRegistration");
    }

    #endregion

    #region Implementation of IMessageHandler<CancelRegistration>

    public void Handle(CancelRegistration message)
    {
        Console.WriteLine("======> handled CancelRegistration");

        MarkAsComplete();
    }

    #endregion
}
4

2 回答 2

2

您的 StartRegistration 处理程序未将 RegistrationID 添加到 Saga 的数据中。因此,您对 ConfigureHowToFindSaga 的覆盖被映射到在处理其他命令时没有值的属性。

于 2012-04-19T18:51:38.573 回答
0

就在今天,我听说 Ninject 不能开箱即用地处理 setter 注入 - 尝试将其切换到构造函数注入,看看是否可行。

于 2012-04-17T21:30:44.617 回答