Question

En essayant de configurer Servicestack.net pour utiliser Nijject comme CIO, je reçois des erreurs faisant référence à diverses liaisons non définies.Principalement pour l'ICACHE CLIENT.

Quelles liaisons spécifiques doivent être créées pour utiliser Ninject correctement?

a actuellement spécifié:

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

note

J'ai créé un IContainerAdapter conformément à la documentation du serviceStack pour mettre en œuvre l'utilisation de NIJECT. (Trouvé ici: ServiceStack Coo Docs )

note 2 Ma méthode de configuration d'APPHOST ressemble à ceci:

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

note 3

J'ai enregistré l'iCacheclient comme suit: Lier (). À ();

Et je reçois maintenant une erreur pointant vers Irequest

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

Adaptateur de conteneur

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>();
    }
}

Était-ce utile?

La solution

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>();
}

Autres conseils

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top