Castle Windsor と構成としてのコード (Castle Windsor の XML なし) を使用して非流暢な NHibernate (NHibernate の xml マッピング) を使用する PersistenceFacility の例はありますか? (ASP.NET MVC)
チュートリアルを実行すると、流暢な NHibernate を使用していますが、私は流暢を使用できません (*.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>());
}
}
必要なのは、Fluent なしで NHibernate をセットアップするための PersistenceFacility 構成です。誰かが非流暢な NHibernate のために NHibernate などをセットアップするコードをデモンストレーションできるか、素晴らしい例/チュートリアル/ブログを教えてくれれば!