Nhibernate 是否通过web.config添加拦截器?亚硝酸铵

Nhibernate 是否通过web.config添加拦截器?亚硝酸铵,nhibernate,configuration,interceptor,Nhibernate,Configuration,Interceptor,我似乎找不到有人通过web.config添加拦截器的例子-这可能吗 是的,我知道事件侦听器,并将在另一个项目上使用它们-但我想看看我是否可以绕过必须在代码中插入拦截器的问题-谢谢你我认为它不受支持,但你可以很容易地从自定义配置部分获取和实例化拦截器: NHibernate.Cfg.Configuration cfg = ... var interceptors = (NameValueCollection) ConfigurationManager.GetSection("nhibernate.

我似乎找不到有人通过web.config添加拦截器的例子-这可能吗


是的,我知道事件侦听器,并将在另一个项目上使用它们-但我想看看我是否可以绕过必须在代码中插入拦截器的问题-谢谢你

我认为它不受支持,但你可以很容易地从自定义配置部分获取和实例化拦截器:

NHibernate.Cfg.Configuration cfg = ...
var interceptors = (NameValueCollection) ConfigurationManager.GetSection("nhibernate.interceptors");
foreach (string k in interceptors)
    cfg.SetInterceptor((IInterceptor) Activator.CreateInstance(Type.GetType(k)));
web.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <configSections>
   <section name="nhibernate.interceptors" type="System.Configuration.NameValueSectionHandler, System" />
 </configSections>
 <nhibernate.interceptors>
    <add key="MyApp.Interceptors.SomeInterceptor, MyApp" value=""/>
    <add key="MyApp.Interceptors.AnotherInterceptor, MyApp" value=""/>
 </nhibernate.interceptors>
</configuration>

我认为它不受支持,但您可以从自定义配置部分轻松获取和实例化拦截器:

NHibernate.Cfg.Configuration cfg = ...
var interceptors = (NameValueCollection) ConfigurationManager.GetSection("nhibernate.interceptors");
foreach (string k in interceptors)
    cfg.SetInterceptor((IInterceptor) Activator.CreateInstance(Type.GetType(k)));
web.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <configSections>
   <section name="nhibernate.interceptors" type="System.Configuration.NameValueSectionHandler, System" />
 </configSections>
 <nhibernate.interceptors>
    <add key="MyApp.Interceptors.SomeInterceptor, MyApp" value=""/>
    <add key="MyApp.Interceptors.AnotherInterceptor, MyApp" value=""/>
 </nhibernate.interceptors>
</configuration>