StructureMap get registered types, not instances
I have a plugin system that allows a user to choose the type of plugin they wish to create (basically this sets up a configuration for a plugin instance).
They choose the plugin type from a se开发者_开发问答lect list. I am using StructureMap to inject an IEnumerable into my MVC controller so that I can then access the FQ type name to use in the select list.
This works fine but I don't really like that I having to create an instance of all the registered plugins just to display a list of them in a select list.
So the question is, can I access the types of IPlugin that are registered with StructureMap?
You should be able to get the instance information by using the Model property of the container:
IContainer container = ObjectFactory.Container;
IEnumerable<InstanceRef> instances = container.Model.AllInstances.
Where(i => i.PluginType.Equals(typeof(IPlugin)));
You can access the Concrete type using:
foreach(var instanceRef in instances)
Console.WriteLine(instanceRef.ConcreteType);
精彩评论