문제

ServiceStack.net을 ioC로 사용하도록 구성하려고하면 다양한 바인딩을 정의하지 않는 오류가 발생합니다.주로 ICACHE 클라이언트 용.

NINJECT를 올바르게 사용하기 위해 특정 바인딩을 생성해야합니다.

현재 다음을 지정했습니다 :

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

메모

i는 in NINJECT의 사용을 구현하기 위해 ServiceStack Documention에 따라 IContainerAdapter를 만들었습니다. ( ServiceStack IOC 문서 )

주 2 AppHost 구성 메서드가 다음과 같습니다.

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

노트 3

i iCacheClient를 다음과 같이 등록했습니다. bind (). ~ ();

이제 irequest 을 가리키는 오류가 발생합니다.

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

컨테이너 어댑터

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

도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top