1

Please help? My NServiceBus endpoint is:

    public class EndpointConfig : IConfigureThisEndpoint
{
    public void Customize(BusConfiguration busConfiguration)
    {
        var windsorContainer = new WindsorContainer();
        windsorContainer.Install(new IocInstaller());

        busConfiguration.UseContainer<WindsorBuilder>(x => x.ExistingContainer(windsorContainer));

        var nhConfiguration = new NHibernate.Cfg.Configuration();
        nhConfiguration.Properties["connection.provider"] = "NHibernate.Connection.DriverConnectionProvider";
        nhConfiguration.Properties["connection.driver_class"] = "NHibernate.Driver.Sql2008ClientDriver";
        nhConfiguration.Properties["dialect"] = "NHibernate.Dialect.MsSql2008Dialect";
        nhConfiguration.GetClassMapping(typeof(ProductAchievementMap));

        busConfiguration.UsePersistence<NHibernatePersistence>().UseConfiguration(nhConfiguration);

        busConfiguration.UseSerialization<XmlSerializer>();
    }
}

My handler is:

    public class ProductAchievementAuditCommandHandler : IHandleMessages<ProductAchievementAuditCommand>
{
    public ISession Session { get; set; }

    public void Handle(ProductAchievementAuditCommand message)
    {
        var productAchievementAudit = new ProductAchievement
        {
            Id = Guid.NewGuid(),
            SapComId = message.SapComId,
            MessageId = message.MessageId
        }; 

        Session.Save(productAchievementAudit);
    }
}

My fluent mapping is:

    public class ProductAchievementMap : ClassMap<ProductAchievement>
{
    public ProductAchievementMap()
    {
        Table("ProductAchievementMessage");
        Id(x => x.Id);
        Map(x => x.SapComId);
        Map(x => x.MessageId);
    }
}

The error I'm getting is:"ERROR NServiceBus.GenericHost Exception when starting endpoint. System.InvalidOperationException: No NHibernate properties found in your config". According to the documentation I need to use busConfiguration.UsePersistence<NHibernatePersistence>().RegisterManagedSessionInTheContainer();. To get public ISession Session { get; set; } in the handler. How do I get the fluent mapping to work? Any help greatly appreciated.

4

1 回答 1

3

我终于想通了万岁!关键是 NServiceBus 5.2 中语法的变化不确定这是否是最好的方法,但它有效。端点配置现在看起来像这样。

    public class EndpointConfig : IConfigureThisEndpoint
{
    public void Customize(BusConfiguration busConfiguration)
    {
        var nhConfiguration = new Configuration();
        nhConfiguration.Properties["connection.provider"] = "NHibernate.Connection.DriverConnectionProvider";
        nhConfiguration.Properties["connection.driver_class"] = "NHibernate.Driver.Sql2008ClientDriver";
        nhConfiguration.Properties["dialect"] = "NHibernate.Dialect.MsSql2008Dialect";
        nhConfiguration.Properties["connection.connection_string"] = @"Data Source=SQL_DEV\DEVELOPMENT;Initial Catalog=SPM.Auditlog;Integrated Security=True";

        var newConfig = Fluently.Configure(nhConfiguration)
            .Mappings(x => {
                                x.FluentMappings.AddFromAssemblyOf<ProductAchievementMap>();
                            }).BuildConfiguration();

        busConfiguration.UsePersistence<NHibernatePersistence>().UseConfiguration(newConfig);
        busConfiguration.UsePersistence<NHibernatePersistence>().RegisterManagedSessionInTheContainer();

        var windsorContainer = new WindsorContainer();
        windsorContainer.Install(new IocInstaller());

        busConfiguration.UseContainer<WindsorBuilder>(x => x.ExistingContainer(windsorContainer));

        busConfiguration.UseSerialization<XmlSerializer>();
    }
}
于 2015-06-05T05:28:15.553 回答