有没有人有使用非流利的 NHibernate(NHibernate 中的 xml 映射)与 Castle Windsor 和代码作为配置的 PersistenceFacility 示例(没有用于 Castle Windsor 的 XML)?(ASP.NET MVC)
通过本教程,他们使用的是 fluent-NHibernate,而我不能使用 fluent(我将通过 *.hbm.XML 配置 NHibernate 类)。
教程> http://docs.castleproject.org/Windsor.Windsor-Tutorial-Part-Six-Persistence-Layer.ashx
Fluent的具体例子> https://github.com/kkozmic/ToBeSeen/blob/master/src/ToBeSeen/Plumbing/PersistenceFacility.cs
public class PersistenceFacility : AbstractFacility
{
protected virtual void ConfigurePersistence(Configuration config)
{
SchemaMetadataUpdater.QuoteTableAndColumns(config);
}
protected virtual AutoPersistenceModel CreateMappingModel()
{
var m = AutoMap.Assembly(typeof(EntityBase).Assembly)
.Where(IsDomainEntity)
.OverrideAll(ShouldIgnoreProperty)
.IgnoreBase<EntityBase>();
return m;
}
protected override void Init()
{
var config = BuildDatabaseConfiguration();
Kernel.Register(
Component.For<ISessionFactory>()
.UsingFactoryMethod(_ => config.BuildSessionFactory()),
Component.For<ISession>()
.UsingFactoryMethod(k => k.Resolve<ISessionFactory>().OpenSession())
.LifestylePerWebRequest()
);
}
protected virtual bool IsDomainEntity(Type t)
{
return typeof(EntityBase).IsAssignableFrom(t);
}
protected virtual IPersistenceConfigurer SetupDatabase()
{
return MsSqlConfiguration.MsSql2008
.UseOuterJoin()
.ConnectionString(x => x.FromConnectionStringWithKey("ApplicationServices"))
.ShowSql();
}
private Configuration BuildDatabaseConfiguration()
{
return Fluently.Configure()
.Database(SetupDatabase)
.Mappings(m => m.AutoMappings.Add(CreateMappingModel()))
.ExposeConfiguration(ConfigurePersistence)
.BuildConfiguration();
}
private void ShouldIgnoreProperty(IPropertyIgnorer property)
{
property.IgnoreProperties(p => p.MemberInfo.HasAttribute<DoNotMapAttribute>());
}
}
我需要的是PersistenceFacility 配置来设置没有 Fluent 的 NHibernate。如果有人可以演示为非流利的 NHibernate 设置 NHibernate 等的代码,或者将我指向一个很棒的示例/教程/博客!