StructureMap: Programmatically retrieves a list of instance keys from StructureMap.config
I have defined a for a specific interface in my StructureMap.config. There can be many different specific types available.
I would like to programmatically get a list of the available instance keys (names) currently available without actually parsing the StructureMap.config file itself. Is there any way to do this?
+2
user196402
source
to share
1 answer
Yes, you can inspect the container using its Model property.
For example, the following code will print the names of all instances of IWidget:
foreach(var instance in container.Model.InstancesOf<IWidget>())
{
Console.WriteLine(instance.Name);
}
+1
Joshua flanagan
source
to share