Przechwytywanie za pomocą Ninject. Nie można załadować IProxyRequestFactory
Uczę się używać wzorca Ninject i Interceptor.
Mam następujący przechwytujący.
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);
}
}
I nazwij klasęMyClass
które otrzymały tylko dwie proste metody, wirtualne, aby umożliwić przechwytywaczom pracę nad nimi. (Dwie metody to Echo i double, co robi to, co mówi ich nazwa.)
Dodałem Ninject, Ninject.Extensions.Interception i Ninject.Extensions.Interception.DynamicProxy do mojego projektu poprzez NuGet.
Dodano następująceusing
sprawozdania.
using Ninject;
using Ninject.Extensions.Interception.Infrastructure.Language;
using Ninject.Extensions.Interception;
Moja główna metoda, która wygląda tak.
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);
}
Dostaję następujący błąd w określonej linii.
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..
Czy ktoś może mi powiedzieć, co robię źle?