本文整理汇总了C#中NHibernate.Cfg.Configuration.GetMappingAssemblies方法的典型用法代码示例。如果您正苦于以下问题:C# NHibernate.Cfg.Configuration.GetMappingAssemblies方法的具体用法?C# NHibernate.Cfg.Configuration.GetMappingAssemblies怎么用?C# NHibernate.Cfg.Configuration.GetMappingAssemblies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NHibernate.Cfg.Configuration
的用法示例。
在下文中一共展示了NHibernate.Cfg.Configuration.GetMappingAssemblies方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureCfgFile
/// <summary>
/// configure with specified nhibernate configuration file.
/// </summary>
/// <param name="configFilePath">physical path of nhibernate configuration file</param>
/// <returns></returns>
protected override NHibernate.Cfg.Configuration ConfigureCfgFile(string configFilePath) {
configFilePath = FileTool.GetPhysicalPath(configFilePath);
if(File.Exists(configFilePath) == false)
throw new FileNotFoundException("NHibernate 환경설정 파일을 찾을 수 없습니다. configFilePath=" + configFilePath);
if(log.IsInfoEnabled)
log.Info("NHibernate Configuration 빌드를 시작합니다... configFilePath=[{0}]", configFilePath);
var cfg = new NHibernate.Cfg.Configuration();
var conventions = new List<IConvention>();
if(Convention != null)
conventions.Add(Convention);
try {
cfg.Configure(configFilePath);
var fluentCfg = Fluently.Configure(cfg);
foreach(var asm in cfg.GetMappingAssemblies()) {
var mapAsm = asm;
fluentCfg.Mappings(m => {
var container = m.FluentMappings.AddFromAssembly(mapAsm);
if(conventions.Count > 0)
container.Conventions.Add(conventions.ToArray());
});
fluentCfg.Mappings(m => m.HbmMappings.AddFromAssembly(mapAsm));
}
// Configuration 파일에서 정의한 Mapping Assembly 외에
// IoC를 통해 NHUnitOfWorkFactory에 할당된 추가 Assembly들도 매핑이 가능하게 열어준다.
//
if(_assemblies != null && _assemblies.Length > 0) {
var loadedAssemblies = cfg.GetMappingAssemblies().ToList();
var assemblies = _assemblies.Where(asm => loadedAssemblies.Contains(asm) == false).ToList();
fluentCfg.Mappings(m => {
assemblies.ForEach(asm => {
var container = m.FluentMappings.AddFromAssembly(asm);
if(conventions.Count > 0)
container.Conventions.Add(conventions.ToArray());
});
assemblies.ForEach(asm => m.HbmMappings.AddFromAssembly(asm));
});
}
cfg = fluentCfg.BuildConfiguration();
}
catch(Exception ex) {
if(log.IsErrorEnabled) {
log.Error("NHibernate 환경설정에 실패했습니다. configFilePath=[{0}]", configFilePath);
log.Error(ex);
}
throw;
}
if(log.IsInfoEnabled)
log.Info("NHibernate Configuration 빌드를 완료했습니다!!! configFilePath=[{0}]", configFilePath);
return cfg;
}