An organizational problem

Ok. I have an organizational problem in my mvc app. Surprised? Thought not. Anyway, here it is. Maybe somebody can help.

The first thing to know is that I have an exntesion method class that adds some methods to ViewDataDictionary for building, caching and fetching SelectList objects. The reason I did it this way is because ViewData is common to both the controller and the view. Here’s an example of one of the methods.

public static void BuildSelectList(this ViewDataDictionary viewData, string key, IEnumerable items, object selectedValue)
{
viewData[key] =
new SelectList(items, selectedValue);
}
 
Now put this out of mind for a moment. In my original concept, the application services operate between the controller and the repositories. In other words, Controllers are injected only with one or more services. Services are injected with one or more repositories (and occasionally an additional service).

This causes a problem in actions where I need to call buildselectlist thusly:


ViewData.BuildSelectList(
“ParentSelectList”, forumRepository.Select(), “Id”, “Title”, model.ParentId);
return[FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] View(model);

[/SIZE][/FONT][/SIZE][/FONT]Notice it needs a repository, but the controller doesn’t have a reference to it. At first I though I should just add a method to the service to forward the data needed, but then on second thought, that seemed to duplicate concerns and I nixed the idea.

I can’t have the service build the list either because I’d have to make it aware of System.Web.Mvc, and I don’t want to do that.

What I tried next was abandon the middle-ware style service, and replaced them with more specific things. In this case IModelService (entity to model mapping), IUpdateService (updates entities from action bound models) and IValidationService. This allowed me to modularize things a bit more and make it work, but the best placement for these three things is in my custom BaseController since all controllers will need these three services. This made the class files for top level controllers now require a using clause for both services and repositories since the constructors need to inject the services into the base class. Really awkward looking. I’m not sure it’s the best solution.

What would you guys advise?