Derik Whittaker

Syndication

News


Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
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
Posted 07-23-2007 5:43 PM by Derik Whittaker

[Advertisement]

Comments

VusCode - Coding dreams since 1998! wrote Design for testability - Structure map (Part 6)
on 03-03-2008 4:59 AM

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

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)