Reputation: 27399
I can't seem to find an example where someone added an interceptor via web.config - is this possible?
And yes I know about event listeners and will be using them on another project - but I wanted to see if I could get around having to inject the interceptor in code - thank you
Upvotes: 1
Views: 1358
Reputation: 99740
I don't think it's supported but you can easily fetch and instantiate interceptors from a custom config section:
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>
Upvotes: 1