Sure I can. The interceptor is very simple, it is a timing
interceptor, it logs the time taken for execution of a method. I am
using NHibernateIntegrationFacilty from Castle and other pieces from
Castle including Windsor, Monorail. Here is how I have hooked up
everything (similar to the approach described in the blog post).
In my container class (this derives from WindsorContainer class), I do
the following:
Kernel.ComponentRegistered += new ComponentDataDelegate
(Kernel_ComponentRegistered);
Environment.BytecodeProvider = new BytecodeProvider(this);
InitalizeFromConfigurationSource(new XmlInterpreter());
this.Kernel.Resolve<NHibernate.Cfg.Configuration>().SetInterceptor(new
WindsorInterceptor(this));
The implementation for ByteCodeProvider and ReflectionOptimizer is
similar to as described in the blog post.
void Kernel_ComponentRegistered(string key, IHandler handler)
{
ComponentModel model = handler.ComponentModel;
//snip code, it registers the interceptor only if some conditions are
met
handler.ComponentModel.Interceptors.Add(new
InterceptorReference("timer-interceptor"));
}
timer-interceptor is registered with the container and is a simple
class like below:
public class TimerInterceptor : IInterceptor
{
private ILogger logger = NullLogger.Instance;
public ILogger Logger
{
get { return logger; }
set { logger = value; }
}
public void Intercept(IInvocation invocation)
{
Stopwatch sw = new Stopwatch();
sw.Start();
invocation.Proceed();
sw.Stop();
Logger.Debug(String.Format("Execution of {0} in {1} took
{2} milliseconds.", invocation.Method.Name,
invocation.Method.DeclaringType.Name, sw.ElapsedMilliseconds));
}
}
Now what is happening is that when my NH entities are regsitered with
the container, it returns a proxy (because of the interceptor) and NH
fails in update saying "No persister found". If I disable the
interceptor, the DI into entities work just fine.
Hope I have shared enough to explain the problem.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---