質問

ServiceStack.netをIOCとして使用するように設定しようとしている場合は、さまざまなバインディングを参照していないエラーが発生しています。主にIcacheクライアント用です。

NINJECTを正しく使用するにはどの特定のバインディングを作成する必要がありますか?

現在指定されています:

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

NINJENTの使用を実装するためにServiceStack文書に従ってIcontainerAdapterを作成しました。 (ここにあります: servicestack ioc docs

注2 My Apphost Configureメソッドは次のようになります。

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

注3

IcacheClientを次のように登録しました。 bind()to();

そして私は今ebest を指しているエラーを得ています

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