我一直在努力寻找这个我们的年龄。当我尝试我的类绑定与拦截我上线无法获得Ninject.Extensions.Interception工作
Kernel.Bind<MyClass>().ToSelf().Intercept().With<ILoggerAspect>();
错误加载Ninject组件IAdviceFactory收到以下异常。没有这样的组件已注册在内核中的组件容器
我已经试过与不LoadExtensions,大约用一个模块来建立我的绑定和我的最后一次尝试看起来像这样
internal class AppConfiguration
{
internal AppConfiguration()
{
var settings = new NinjectSettings() { LoadExtensions = false };
Kernel = new StandardKernel(settings);
Load();
}
internal StandardKernel Kernel { get; set; }
public static AppConfiguration Instance
{
get { return _instance ?? (_instance = new AppConfiguration()); }
}
private static AppConfiguration _instance;
private void Load()
{
Kernel.Bind<ILoggerAspect>().To<Log4NetAspect>().InSingletonScope();
Kernel.Bind<MyClass>().ToSelf().Intercept().With<ILoggerAspect>();
}
internal static StandardKernel Resolver()
{
return Instance.Kernel;
}
}
我的记录器属性看起来像这样
public class LogAttribute : InterceptAttribute
{
public override IInterceptor CreateInterceptor(IProxyRequest request)
{
return request.Context.Kernel.Get<ILoggerAspect>();
}
}
我的截击这样
public class Log4NetAspect : SimpleInterceptor, ILoggerAspect
{
protected override void BeforeInvoke(IInvocation invocation)
{
Debug.WriteLine("Running " + invocation.ReturnValue);
base.BeforeInvoke(invocation);
}
public new void Intercept(IInvocation invocation)
{
try
{
base.Intercept(invocation);
}
catch (Exception e)
{
Debug.WriteLine("Exception: " + e.Message);
}
}
protected override void AfterInvoke(IInvocation invocation)
{
Debug.WriteLine("After Method");
base.AfterInvoke(invocation);
}
}
我试图用Nuget抓住他们,你需要两个还是只有一个? – 2012-04-03 07:53:03
谢谢,就是这样。为什么nuget软件包没有添加其中的一个作为Default?从使用它的开发者那里,它没有什么区别。 – 2012-04-04 00:05:36
有用的知道,我试图让它的工作使用LoadExtensions = false,并且无法从内核获取任何实例 – user1039513 2012-08-29 08:06:11