Posts

Showing posts from April, 2021

Interception using NInject

  Interception using NInject      NInject is a DI (Dependency Inversion) container. NInject can be used to inject classes and obtain instances of classes. Interception allows method invocations to be intercepted such as before a method call and after a method call. This is useful for logging, exception handling etc... There are several use cases. This blog post just shows the overall concept. The use cases can be handled if the concepts are understood. The following NuGet packages need to be installed: Ninject.Extensions.Interception.DynamicProxy Ninject.Extensions.Interception The IInterceptor interface can be implemented. This interface has only one method Intercept with the following signature: Intercept(IInvocation invocation) The parameter invocation has several properties with information regarding the target method, parameters being passed etc... invocation.Proceed() can be used for invoking the target method, even the result can be obtained. Wrapping this in a try..catch block