You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(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.
The text was updated successfully, but these errors were encountered:
I see. How would I then inject it into BusinessLogic?
Although it wouldn't solve my problem, I tried WhenInjectedInto<Func<IDb>> but that didn't work either. Any suggestions?
(Not sure if this is a bug in Ninject itself or in the factory extension)
In the following example
BusinessLogic
gets the factories forMySqlDb
andSqliteDb
but not forMsSqlDb
.MsSqlDb
is bound usingWhenInjectedInto<T>
, but still it should work, shouldn't it?I also tried injecting it as
IEnumerable<Func<IDb>>
but that gets me only oneFunc
and invoking that fails with anActivationException
that there are too many bindings:The text was updated successfully, but these errors were encountered: