Multiple Ninject 3 Bindings

My question is really a repetition of the old question posted here: Multiple Ninject 2.2 Bindings

It seems that someone was going to deal with this back in 2011. Does anyone know if there is a way to disable such warnings in Ninject? Or some other workaround?

EDIT

In response to @BatteryBackupUnit, here is my exact problem:

I have several libraries ... and in my main library I am doing something like this:

  • Find all assemblies referenced by the host application (including the host)
  • Find all types that inherit IDependencyfrom all of these assemblies.
  • Automatically register all of them as transitional

Then from another library (which the link to the host application may or may not reference), I have the following:

Kernel.Bind<IDbContextFactory>().To<DbContextFactory>().InSingletonScope();

IDbContextFactory IDependency, , , (singleton).

( ) , Autofac, Ninject , .

... " " (- ).

+1
1

Ninject . :

public interface IFoo<T> { }
public class Foo<T> : IFoo<T> { }
public class StringFoo : IFoo<string> {}

:

var kernel = new StandardKernel();
kernel.Bind(typeof(IFoo<>)).To(typeof(Foo<>));
kernel.Bind<IFoo<string>>().To<StringFoo>();

var intFooInstance = kernel.Get<IFoo<int>>();
var stringFooinstance = kernel.Get<IFoo<string>>();

Works.

, , ninject 3 - , ninject 2.2.

, . , , . , : https://github.com/ninject/ninject/wiki/Contextual-Binding

. . .: https://github.com/ninject/ninject/wiki/Contextual-Binding#simple-constrained-resolution-named-bindings

, .Bind<IFoo>().To<Foo>(); .When(...), :

.Bind<IFoo>().To<SpecialFoo>().When(ctx => ...)

. https://github.com/ninject/ninject/wiki/Contextual-Binding#specifying-constraints-on-the-type-binding-using-arbitrary-elements-of-the-resolution-request-context

, .

0

Source: https://habr.com/ru/post/1792745/


All Articles