Is there a way to request an instance from StructureMap ObjectFactory by type string name? For example, it would be nice to do something like this:
var thing = ObjectFactory.GetInstance("Thing");
This uses a messaging script in which the message is very general and contains only the task name. The handler receives the message, gets the task name from the message, and retrieves the type name of the associated task runner from the configuration database. StructureMap scans all the assemblies in the directory, and one of them (presumably) will contain the type returned from the config database, which must then be created.
Another option is to capture an instance of Type by doing the following:
var type = Type.GetType("Thing");
But the problem is that the assembly may or may not / may not be loaded into the AppDomain, so a reflection call is not always possible.
source
share