Question

Situation:

Interfaces:

IRepository<T>
IMyModelRepository : IRepository<MyModel>

Classes:

Repository<T> : IRepository<T>
MyModelRepository : Repository<MyModel>, IMyModelRepository

Bindings:

kernel.Bind(typeof(Namespace.IRepository<>)).To(typeof(Namespace.Repository<>)).InRequestScope();
kernel.Bind(typeof(Namespace.IRepositoryInternal<>)).To(typeof(Namespace.Repository<>)).InRequestScope();
kernel.Bind(typeof(Namespace.IMyModelRepository)).To(typeof(NameSpace.MyModelRepository)).InRequestScope();

kernel.Bind(scanner => scanner
                .FromAssemblyContaining(typeof(Namespace.SomeService))
                .SelectAllClasses()
                .Excluding<Namespace.MyModelRepository>()
                .BindDefaultInterfaces()
                .Configure(binding => binding.InRequestScope()));

Injection:

readonly IRepository<MyModel> _MyModelRepository; //this is the property, injection is constructor injection

Problem:

Error activating IRepository{WarningModel} More than one matching bindings are available. Activation path: 5) Injection of dependency IRepository{MyModel} into parameter MyModelRepository of constructor of type AnotherService

What am i missing? where is the multiple binding?

If this info is not enough, i can provide extra info.

Was it helpful?

Solution

The problem was .BindDefaultInterfaces(). It should have been .BindDefaultInterface().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top