C# Ninject:按属性拦截,而不从InterceptAttribute派生

C# Ninject:按属性拦截,而不从InterceptAttribute派生,c#,dependency-injection,attributes,ninject,aop,C#,Dependency Injection,Attributes,Ninject,Aop,我正在寻找一种使用Ninject将拦截器连接到基于特定属性的方法调用的方法。Ninject提供了InterceptAttribute基类来实现这一点,这非常简洁,但是我希望通过自定义属性来实现这一点。原因是我想用与业务相关的属性来装饰某些域服务接口,所以我不能让任何东西与其中的框架紧密耦合 这是可能的吗?您可以从Execute(IPlan计划)方法派生并重写该方法(可能还包括RegisterClassInterceptors),以使用您自己的属性类型,而不是ninject的InterceptAt

我正在寻找一种使用Ninject将拦截器连接到基于特定属性的方法调用的方法。Ninject提供了
InterceptAttribute
基类来实现这一点,这非常简洁,但是我希望通过自定义属性来实现这一点。原因是我想用与业务相关的属性来装饰某些域服务接口,所以我不能让任何东西与其中的框架紧密耦合

这是可能的吗?

您可以从
Execute(IPlan计划)
方法派生并重写该方法(可能还包括
RegisterClassInterceptors
),以使用您自己的属性类型,而不是ninject的
InterceptAttribute

然后需要将实现注册为内核组件:

this.Kernel.Components.Add<IPlanningStrategy, MyInterceptorRegistrationStrategy>();
(另见)

Kernel.InterceptAround<CustomerService>(
    s=>s.GetAllCustomers(),
    invocation =>logger.Info("Retrieving all customers..."),
    invocation =>logger.Debug("Customers retrieved"));