Have ever wanted to use a concrete class as both the the PluginFamily and Plugable (information on StructureMap's attributes here) type in StructureMap? I know I have, just today in fact (not the first time, but thought I would post about it this time) I needed to do just this. Why would I want to use a concrete class as both PluginFamily and Plugable type you may ask. Well in this case because I wanted to use DI to inject my configuration class into one of my objects (via constructor injection) and did not think it was worth the effort to create an interface.
Normally if you were use an interface as the PluginFamily and a concrete class as the Plugable, your code would look something like below.
Interface
[PluginFamily("FamilyNameGoesHere")]
public interface IFoo
{
Concrete
[Pluggable("FamilyNameGoeshere")]
public class Foo : IFoo
{
Do have your concrete class act as both you simply combine the two as such
[PluginFamily("FamilyNameGoesHere"), Pluggable("FamilyNameGoeshere")]
public class ConcreateWithNoInterface
{
Keep in mind, that when you do not use interfaces with DI, you are taking away a lot of the power and flexibility that DI provides you. But there are cases from time to time where this situation comes into play.
Till next time,
Posted
07-23-2007 5:43 PM
by
Derik Whittaker