Derik Whittaker



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
StructureMap and Loaded Plugins Gotcha

One of the really great things about the latest release of StructureMap is that I do not need to register objects by default if they follow a standard convention (i.e. if I want to register a controller called ‘AuthorController’ and accessed via ‘AuthorController’ I do not need to do anything, SM is smart enough to map this for me).  However, as great as this is, there is one slight issue (may be a bug, do not know need to follow up with Jeremy).

In the Dimecasts codebase I put the logic to register routes for each controller into each controller.  I then at startup time I loop though all the controllers and register each route.

The code below is the logic I do for performing this registration

	var controllerInstances = ObjectFactory.Model.PluginTypes.Where(x => typeof(BaseController).IsAssignableFrom(x.PluginType));

	foreach (var controllerInstance in controllerInstances) 

	var instance = (BaseController)ObjectFactory.GetInstance(controllerInstance.PluginType); 




All of this works and works well but when i added a new controller to the application and did not manually register it (aka using the convention of configuration feature) I was not able to load the new controller.  I was a little stumped at first, but then it downed on me that since i am not pre-registering the controller with StructureMap it may not now how to find it.  To test this theory i simply manually registered the controller and bam, all worked.

I thought I would share this incase anyone else had the same issue.

Till next time,

[--- Remember to check out ---]

Posted 12-18-2008 8:33 PM by Derik Whittaker


About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)