I'm used to Ninject, and for a specific project, Iām invited to learn Unity.
There is one thing, I can not find information on how to do this.
In Ninject, I can specify:
Bind<IWarrior>().To<Samurai>().Named("Samurai"); Bind<IWarrior>().To<Ninja>().Named("Ninja"); Bind<IWeapon>().To<Katana>().WhenInjectedInto(typeof(Samurai)); Bind<IWeapon>().To<Shuriken>().WhenInjectedInto(typeof(Ninja));
And then, when someone asks for a warrior named samurai, the samurai comes with a canana, and the ninja comes with a shuriken. As it should be.
I do not want to refer to the container of warriors to get the appropriate weapons, and I do not want to pollute the model with attributes (located in another assembly that does not have a reference to ninject or unity)
PD: I'm looking for a way to code, not through the xml configuration.
ioc-container unity-container ninject
David lay
source share