I have started to use Ninject today because Structuremap let me down big time.
I hit an issue when I began registering the same types with the same interfaces but I have have named them (as shown below).
kernel.Bind<IDataContextAsync>().To<DbGeoContext>().InRequestScope().Named("DbGeoContext");
kernel.Bind<IDataContextAsync>().To<DbEspContext>().InRequestScope().Named("DbEspContext");
IParameter geoUnitOfWorkDbContext = new ConstructorArgument("dataContext", kernel.Get<IDataContextAsync>("DbGeoContext"));
IParameter espUnitOfWorkDbContext = new ConstructorArgument("dataContext", kernel.Get<IDataContextAsync>("DbEspContext"));
kernel.Bind<IUnitOfWorkAsync>().To<UnitOfWork>().Named("UnitOfWorkGeoContext").WithConstructorArgument(geoUnitOfWorkDbContext);
kernel.Bind<IUnitOfWorkAsync>().To<UnitOfWork>().Named("UnitOfWorkEspContext").WithConstructorArgument(espUnitOfWorkDbContext);
**Fails here with: Error activating IDataContextAsync
More than one matching bindings are available.**
var t1 = kernel.Get("UnitOfWorkGeoContext"); var t2 = kernel.Get("UnitOfWorkEspContext");
Could someone help me figure out what is going on here and how to fix it?
I understand at runtime Ninject wont be able to figure out which instance to inject, but I though this was what the 'Named' instances was for?
Thanks
Namedattribute - David Pine.Named("SomeUniqueString")-- you must have theNamedattribute in the constructor so that it knows how to resolve. - David Pine