Lou Haskett

Sponsors

The Lounge

Wicked Cool Jobs

Syndication

Archives

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
Design Considerations: StructureMap Configuration and Plugin Keys

I started playing with StructureMap recently. I am struggling with how to design my code's interaction with StructureMap when it comes to the configuration and use of plugin keys. If you have any insights or experience with this, please let me know!

1. Configuration via StructureMap.config

Pros:
* Separation of Concerns
  * My pluggable code doesn't have to know that its going to be used with StructureMap. A big pro!
* One Stop Shop
  * One file to look at to figure out how the application is configured.
* "Look Ma, no hands"
   * To change my plugin configuration or add a new plugin type i don't have to recompile.

Cons:
* One Stop Shop
   * I don't know how to make separate config files for each pluggable component, so if I have several components used in different apps, i have to cut and paste config file information between them.
   * This configuration file could get to be pretty big...
* "Silent Death"
   * It doesn't compile, so i won't know if somethings broken till runtime. I haven't learned about it yet, but it looks like StructureMapDoctor could help with this?
* Magic Strings
   * Magic everywhere! One typo and things can get pretty ugly. What do i do about those Plugin Keys? Anyone who wants anything other than the default instance has to know about the magic concrete key string!

2. Configuration via Attributes

Pros:
* Close to Home
   * Information about each pluggable type is local to the type. Makes it easier to find and manage configuration information.

Cons:
* "He knows too much"
   * Each interface and concret class now knows that its a StructureMap plugin family or pluggable type. Not good if i change my mind about which IoC/DI tool to use later.
* Magic Strings
   * Less string magic than the config file, but i've still got those plugin keys that consumers need to know about.
* "Bad Touch"
   * I've gotta change the code to adjust my configuration. Though usually if that happens i'm guess your going to have to recompile anyway...

Magic Plugin Key Solution?

I tried to solve my magic plugin key issue by create a separate plugin key assembly that just has const strings in it for each plugin key. I decided that for each pluggable assembly XXX i had, i would create an assembly XXX.PluginKey. In the PluginKey assembly I put static classes with the same name as the plugin interface that contain nothing but my plugin keys. I made the strings guid's to help discourage people from using the strings to cut and paste.

So if I use attribute based config I can setup a plugin family like so:

And setup a pluggable type like so:

And finally retrieve it like this:

I'm a little iffy on the design decision to make my plugin key class have the same name as the plugin families interface. But at the same time i thought it would make it pretty damn clear what its holding keys for. And I like the syntax look too. So this kind of solves my magic plugin key issue. I'm not sure I like it though, as I have another assembly floating around. Perhaps I've overcomplicated things... but I just don't like those strings!

So please, let me know about which kind of configuration you prefer, why you do, and how you handle your plugin keys. Or other pros / cons i've missed. I'd like to know! If your a fan of a different IoC/DI tool that you think deals with these issues more elegantly, I'd like to know that too.

Peace.


Posted 06-26-2007 8:47 PM by Louis Haskett

[Advertisement]

Comments

Derik Whittaker wrote re: Design Considerations: StructureMap Configuration and Plugin Keys
on 06-27-2007 8:07 AM

Lou,

I guess one possible way to look at this is how is the application going to be deployed?  If this application going to be deployed to the general public?  Is this going to be deployed in a controlled environment?

If the application is going to be deployed to the general public maybe using attributes is the best thing.  Why, well real hard for some knucklehead to change the config information with attributes.  Where as if it is in the config file, they can simply open the file and mess it all up.

If the application is going to be deployed in a controlled environment such as in a retail store, then maybe config files make more sense.  In the controlled environment you may not have to worry about the file being edited since you can restrict access to the file.

My 2Cents

Add a Comment

(required)  
(optional)
(required)  
Remember Me?

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
<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)