I'm looking at the controllers in my website, and most of their constructors look like this:
public SomeController(
IServiceOne serviceOne,
IServiceTwo serviceTwo,
ILoggingService loggingService,
IGeospatialService geoSpatialService)
{
// copy to class variables.
}
In other words, it's very hairy and makes refactoring difficult. Some controllers have around 8 dependencies.
Is there any way i can somehow "group" these dependencies into one of more buckets?
For example, ILoggingService
is required in every controller, IGeospatialService
is required by controllers who do spatial stuff, and IServiceOne
and IServiceTwo
is only required in certain cases.
I would like to see something like this:
public SomeController(
ICoreServicesGroup coreGroup,
ISomeNameForServicesGroup serviceGroup)
{
// copy to class variables.
}
I'm thinking it would be good to introduce some OO techniques, such as having a "base" depedency class, which takes a ILoggingService
in it's protected ctor. Then you might have another child dependency which inherits, etc.
Has anyone done this before? Is this something StructureMap can do for me, or is it simply me rolling my own basic code?