ninject-interception

Interception with Ninject. Fails to load IProxyRequestFactory

大憨熊 提交于 2019-12-04 08:00:58
I'm learning to use Ninject and Interceptor pattern. I have the following interceptor. public class MyInterceptor:IInterceptor { public void Intercept(IInvocation invocation) { Console.WriteLine("Pre Execute: " + invocation.Request.Method.Name); foreach (var param in invocation.Request.Arguments) { Console.WriteLine("param : " + param); } invocation.Proceed(); Console.WriteLine("Post Execute: " + invocation.Request.Method.Name); Console.WriteLine("Returned: " + invocation.ReturnValue); } } And have a class named MyClass which got nothing but 2 simple methods, virtual to allow the interceptors

Making Ninject Interceptors work with async methods

半腔热情 提交于 2019-12-04 07:21:14
I am starting to work with ninject interceptors to wrap some of my async code with various behaviors and am having some trouble getting everything working. Here is an interceptor I am working with: public class MyInterceptor : IInterceptor { public async void Intercept(IInvocation invocation) { try { invocation.Proceed(); //check that method indeed returns Task await (Task) invocation.ReturnValue; RecordSuccess(); } catch (Exception) { RecordError(); invocation.ReturnValue = _defaultValue; throw; } } This appears to run properly in most normal cases. I am not sure if this will do what I expect

Ninject. Strange intercept to inner set-properties

安稳与你 提交于 2019-12-02 18:10:11
问题 Domain object: TargetObject.cs public class TargetObject { public virtual ChildTargetObject ChildTargetObject { get { return ChildTargetObjectInner; } set { ChildTargetObjectInner = value; } } public virtual ChildTargetObject ChildTargetObjectInner { get; set; } } Configuration and test: var settings = new NinjectSettings { InjectNonPublic = true, AllowNullInjection = true }; var kernel = new StandardKernel(settings); kernel.Bind<TargetObject>().ToSelf(); kernel.InterceptReplaceSet

Ninject. Strange intercept to inner set-properties

旧巷老猫 提交于 2019-12-02 08:52:37
Domain object: TargetObject.cs public class TargetObject { public virtual ChildTargetObject ChildTargetObject { get { return ChildTargetObjectInner; } set { ChildTargetObjectInner = value; } } public virtual ChildTargetObject ChildTargetObjectInner { get; set; } } Configuration and test: var settings = new NinjectSettings { InjectNonPublic = true, AllowNullInjection = true }; var kernel = new StandardKernel(settings); kernel.Bind<TargetObject>().ToSelf(); kernel.InterceptReplaceSet<TargetObject>(t => t.ChildTargetObjectInner, (inv) => { inv.Proceed(); // <= we never step here. Why? } ); var o

How to intercept all the ASP.NET WebApi controller action methods calls with Ninject interception for logging?

霸气de小男生 提交于 2019-11-30 11:03:59
问题 Our company has the need to log certain things each time one of our action methods of our ASP.NET WebApi controllers gets called. Since we use Ninject for the DI right now, we'd like to use it also for this purpose. This is what I have tried so far. I have Ninject, Ninject.Extensions.Interception and Ninject.Extensions.Interception.DynamicProxy installed through NuGet and I have the following module public class InterceptAllModule : InterceptionModule { public override void Load() { Kernel

How to intercept all the ASP.NET WebApi controller action methods calls with Ninject interception for logging?

匆匆过客 提交于 2019-11-29 23:36:00
Our company has the need to log certain things each time one of our action methods of our ASP.NET WebApi controllers gets called. Since we use Ninject for the DI right now, we'd like to use it also for this purpose. This is what I have tried so far. I have Ninject, Ninject.Extensions.Interception and Ninject.Extensions.Interception.DynamicProxy installed through NuGet and I have the following module public class InterceptAllModule : InterceptionModule { public override void Load() { Kernel.Intercept(p => p.Request.Service.Name.EndsWith("Controller")).With(new TimingInterceptor()); } } Where

Ninject Intercept any method with certain attribute?

百般思念 提交于 2019-11-28 08:26:33
How can I get Ninject.Extensions.Interception to basically let me bind a specific interceptor to any method that has an attribute... psudocode: Kernel.Intercept(context => context.Binding.HasAttribute<TransactionAttribute>()) .With<TransactionInterceptor> With a class like: public SomeClass { [TransactionAttribute] public void SomeTransactedMethod() { /*do stuff */ } } Assuming that you are using Ninject.Extensions.Interception this should do the trick public class TransactionInterceptor : IInterceptor { public void Intercept(IInvocation invocation) { // Do something... } } public class

Ninject Intercept any method with certain attribute?

若如初见. 提交于 2019-11-27 02:19:24
问题 How can I get Ninject.Extensions.Interception to basically let me bind a specific interceptor to any method that has an attribute... psudocode: Kernel.Intercept(context => context.Binding.HasAttribute<TransactionAttribute>()) .With<TransactionInterceptor> With a class like: public SomeClass { [TransactionAttribute] public void SomeTransactedMethod() { /*do stuff */ } } 回答1: Assuming that you are using Ninject.Extensions.Interception this should do the trick public class TransactionInterceptor