Devlico.Us
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @devlicious

Derik Whittaker

Thoughts on Software Development, .Net, OOP, Design Patterns and all things cool



StructureMap Tip: Using Concrete classes as a PluginFamily

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,


kick it on DotNetKicks.com


Comments

VusCode - Coding dreams since 1998! said:

On my quest to design for testability, I've already covered: Part 1 - Separation of concerns (SOC

# March 3, 2008 4:59 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Derik Whittaker

Derik is a .Net Developer/Architect specializing in WinForms working out the northern suburbs of Chicago. He is also believer and advocate for Agile development including SCRUM, TDD, CI, etc.

When Derik is not writing code he can be found spending time with his wife and young son, climbing on his bouldering wall, watching sports (mostly baseball), and generally vegging out. Check out Devlicio.us!

Our Sponsors

Red-Gate!