Domanda

Nel tentativo di configurare ServiceStack.net per utilizzare Ninjey come IOC, sto ottenendo errori che si riferiscono a vari attacchi che non vengono definiti.Principalmente per il client Icache.

Quali collegamenti specifici devono essere creati per utilizzare Ninjojey correttamente?

attualmente specificato:

Bind<ISessionFactory>().To<SessionFactory>();//Is this correct/needed?
.

Nota

Ho creato un iContainerAdapter secondo la documentazione del ServiceStack per implementare l'uso di ninject. (Trovato qui: Servicestack IOC Docs )

Nota 2 Il mio Apphost Configure Method è simile a questo:

public override void Configure(Funq.Container container)
{
        IKernel kernel = new StandardKernel(new BindingModule());
        container.Adapter = new NinjectContainerAdapter(kernel);
}
.

Nota 3

Ho registrato l'Icacheclient come segue: BIND (). A ();

E ora sto ottenendo un errore che punta a Irequest

Error activating IRequestLogger\nNo matching bindings are available, and the type is not self-bindable
.

adattatore contenitore

public class NinjectContainerAdapter : IContainerAdapter
{
    private readonly IKernel _kernel;

    public NinjectContainerAdapter(IKernel kernel)
    {
        this._kernel = kernel;
    }

    public T TryResolve<T>()
    {
        return this._kernel.Get<T>();
    }

    public T Resolve<T>()
    {
        return this._kernel.Get<T>();
    }
}
.

È stato utile?

Soluzione

Have you injected your Container adapter with:

container.Adapter = new NinjectIocAdapter(kernel);

If so, try also make your AppHost class internal if you haven't done so. There should only be 1 instance of AppHost and some IOC's like to create their own instance, wiping out all the configuration from the first one.

The behavior you're getting sounds like Ninject is complaining about unresolved dependencies. Make sure you get Ninject to return null with Unresolved dependencies by using kernal.TryGet<T> in your Container Adapter, e.g:

public T TryResolve<T>()
{
    return this._kernel.TryGet<T>();
}

Altri suggerimenti

You need to write your own IContainerAdapter and then set Container.Adapter in your AppHost

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top