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 www.dimecasts.net ---]
12-18-2008 8:33 PM