我有通过NuGet安装的Ninject,Ninject.Extensions.Interception和Ninject.Extensions.Interception.DynamicProxy,我有以下模块
public class InterceptAllModule : InterceptionModule
{
public override void Load()
{
Kernel.Intercept(p => (true)).With(new TimingInterceptor());
}
}
TimingInterceptor是
public class TimingInterceptor : SimpleInterceptor
{
readonly Stopwatch _stopwatch = new Stopwatch();
protected override void BeforeInvoke(IInvocation invocation)
{
_stopwatch.Start();
}
protected override void AfterInvoke(IInvocation invocation)
{
_stopwatch.Stop();
string message = string.Format("[Execution of {0} took {1}.]",invocation.Request.Method,_stopwatch.Elapsed);
Log.Info(message + "\n");
_stopwatch.Reset();
}
}
现在,当我尝试使用ninject内核挂起模块,然后运行我的网站
var kernel = new StandardKernel(new InterceptAllModule());
我收到了以下错误,
Could not load type 'Castle.Proxies.Func`1Proxy' from assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=a621a9e7e5c32e69' because the parent type is sealed.
基本上,每当调用一个action方法时,我都会尝试为我的ASP.NET MVC应用程序进行日志记录。我想记录某些事情。但不知道如何解决这个错误。有经验的人可以指出我做错了吗?感谢。