ninject interception with attribute

337 views Asked by At

I'm trying to use ninject interception in my project for logging exceptions. On the line

public override void Load()
{
     this.Bind<IPoShippingRepository>().To<PoShippingRepository>().Intercept().With<ExceptionInterceptor>();
}

I have got an error: Error loading Ninject component IAdviceFactory No such component has been registered in the kernel's component container. Suggestions:
1) If you have created a custom subclass for KernelBase, ensure that you have properly implemented the AddComponents() method. 2) Ensure that you have not removed the component from the container via a call to RemoveAll().
3) Ensure you have not accidentally created more than one kernel.

Ninject initializing is simple:

private static IKernel _kernel;

public UnitOfWork()
{
      _kernel = new StandardKernel(new DomainNinjectModule());
}

...

public class DomainNinjectModule : NinjectModule
    {
        public override void Load()
        {
            this.Bind<IPoShippingRepository>().To<PoShippingRepository>().Intercept().With<ExceptionInterceptor>();
        }
    }

class ExceptionInterceptor : IInterceptor
    {
        private eKindOfLog _kindOfLog;

        public ExceptionInterceptor(eKindOfLog kindOfLog)
        {
            _kindOfLog = kindOfLog;
        }

        public void Intercept(IInvocation invocation)
        {
            try
            {
                invocation.Proceed();
            }
            catch (Exception ex)
            {
                switch (_kindOfLog)
                {
                    case eKindOfLog.Sql:
                        SimpleLog.LogSqlError(ex);
                        break;
                    case eKindOfLog.Error:
                        SimpleLog.LogSqlError(ex);
                        break;
                }
            }
        }
    }

I installed Ninject.dll, Ninject.Extensions.Interception.dll and Ninject.Extensions.Interception.DynamicProxy.dll. Method where I used interception attribute is public and virtual. Please, help what have I done wrong?

0

There are 0 answers