I’m trying to find an IOC container that will allow me to have mapping data for a field stored in a database and resolve the interface or object that needs resolved via a string value pulled from the database.
Most of the examples I have seen are using interfaces hard coded in code, I want the interface that needs to be resolved to be dynamic.
This is what I usually see:
var taskController = container.Resolve<ITaskController>();
This is what I would like to see:
var strTaskController = "ITaskController";
var taskController = container.Resolve(strTaskController);
I’m sure I could look through the documentation for all the IOC containers but I am hoping this is an easy question for someone with more IOC experience.
Using Unity you can do what you’re looking for. Basically, if you know the full type name, you can do this first:
EDIT: Based on the comment, here’s another approach: