我通过 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.
基本上,每当调用操作方法时,我都会尝试为我的 ASP.NET MVC 应用程序进行日志记录,我想记录某些事情。但不知道如何解决这个错误。有经验的人可以指出我做错了什么吗?谢谢。