I'm new to Unity Dependency Injection and have a question thats probably very straight forward..
I would like to register type mappings based on configuration pulled from my database model. How and what's the best way to do this?
For example would I do something like this?
myContainer.RegisterType<IMyType, /*My dynamic config value*/>();
Thanks in advance
You could specify target types in your database using assembly qualified names
IUnityContainer container = new UnityContainer();
//container.RegisterType<IFoo,Foo>();
Type to = Type.GetType("TestApp.Foo, TestApp");
container.RegisterType(typeof(IFoo),to);
var foo = container.Resolve<IFoo>();
Assert.IsInstanceOf<Foo>(foo);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With