
February 22, 2009 13:00 by
Simon
I had a similar problem to solve in .Net to the one I solved in Java using the ServiceLocator class. I moved the NHibernateSessionManager to a library but needed a way of registering project specific interceptors. Here is the code:
private void RegisterInterceptor()
{
if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["HBM_DAL"]))
{
HibernateInterceptor interceptor = new HibernateInterceptor();
foreach (Type t in Assembly.Load(ConfigurationManager.AppSettings["HBM_DAL"]).GetTypes())
{
if (t.GetInterface("IInterceptorListener") != null)
{
interceptor.Register((IInterceptorListener)Activator.CreateInstance(t));
}
}
RegisterInterceptor(interceptor);
}
}
The following entry needed to be added to App.config:
<appSettings>
<add key="HBM_DAL" value="Trigger.Side.Services.DataAccess" />
</appSettings>
902379c3-95d2-4fe8-8e9b-fd65d60b464c|0|.0