Intercepção com Ninject. Não carrega o IProxyRequestFactory
Estou aprendendo a usar o padrão Ninject e Interceptor.
Eu tenho o seguinte interceptador.
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);
}
}
E ter uma aula chamadaMyClass
que não tem nada além de 2 métodos simples, virtuais para permitir que os interceptadores trabalhem neles. (Dois métodos são Echo e double, que faz o que seu nome diz.)
Eu adicionei Ninject, Ninject.Extensions.Interception e Ninject.Extensions.Interception.DynamicProxy ao meu projeto via NuGet.
Adicionado seguindousing
afirmações.
using Ninject;
using Ninject.Extensions.Interception.Infrastructure.Language;
using Ninject.Extensions.Interception;
Meu método principal, que faz o bootstrapping se parece com isso.
static void Main(string[] args)
{
MyClass o = null;
using (IKernel kernel = new StandardKernel())
{
kernel.Bind<MyClass>().ToSelf().Intercept().With(new MyInterceptor());
o = kernel.Get<MyClass>();
}
o.Echo("Hello World!"); // Error
o.Double(5);
}
Estou recebendo o seguinte erro na linha especificada.
Error loading Ninject component IProxyRequestFactory
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..
Alguém pode me dizer o que estou fazendo errado?