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 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); 

	instance.RegisterRoutes(RouteTable.Routes); 

	}

 

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 www.dimecasts.net ---]


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

[Advertisement]

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)