-
Notifications
You must be signed in to change notification settings - Fork 36
Open
Description
(Not sure if this is a bug in Ninject itself or in the factory extension)
In the following example BusinessLogic
gets the factories for MySqlDb
and SqliteDb
but not for MsSqlDb
. MsSqlDb
is bound using WhenInjectedInto<T>
, but still it should work, shouldn't it?
public class NinjectTest
{
[Fact]
public void ShouldLazilyCreateObjects()
{
var kernel = new StandardKernel();
kernel.Bind<BusinessLogic>().ToSelf();
kernel.Bind<IDb>().To<MsSqlDb>().WhenInjectedInto<BusinessLogic>().InTransientScope();
kernel.Bind<IDb>().To<MySqlDb>().InTransientScope();
kernel.Bind<IDb>().To<SqliteDb>().InTransientScope();
var bl = kernel.Get<BusinessLogic>();
Assert.Equal(3, bl.DbFactories().Count());
}
}
public interface IDb { }
public class SqliteDb : IDb { }
public class MySqlDb : IDb { }
public class MsSqlDb : IDb { }
public class BusinessLogic
{
public IEnumerable<Func<IDb>> DbFactories { get; }
public BusinessLogic(IEnumerable<Func<IDb>> dbFactories)
{
DbFactories = dbFactories;
}
}
I also tried injecting it as IEnumerable<Func<IDb>>
but that gets me only one Func
and invoking that fails with an ActivationException
that there are too many bindings:
An exception of type 'Ninject.ActivationException' occurred in Ninject.dll but was not handled in user code
Additional information: Error activating IDb
More than one matching bindings are available.
Matching bindings:
1) binding from IDb to MySqlDb
2) binding from IDb to SqliteDb
Activation path:
1) Request for IDb
Suggestions:
1) Ensure that you have defined a binding for IDb only once.
Metadata
Metadata
Assignees
Labels
No labels