Consider the below:
public class DependencyA {}
public class DependencyB {}
public class DependencyC {}
public class DependencyD {}
public class Service1
{
public Service1(DependencyA a, DependencyB b, DependencyC c, DependencyD d) { ... }
}
public class Service2
{
public Service2(DependencyA a, DependencyB b, DependencyC c, DependencyD d) { ... }
}
public class Service3
{
public Service3(DependencyA a, DependencyB b, DependencyC c, DependencyD d) { ... }
}
I am finding that many of my services are dependent on multiple common components, and am thinking of implementing a catch all solution like below (all wired up through Windsor) to save repetition of code in the Service constructors.
public class DependencyContainer
{
public DependencyA A { get; set; }
public DependencyB B { get; set; }
public DependencyC C { get; set; }
public DependencyD D { get; set; }
}
public class Service1
{
public Service1 (DependencyContainer container) { ... }
}
Alternatively I could create a ServiceBase class.
public class ServiceBase
{
public DependancyA A { get; set; }
public DependancyB B { get; set; }
public DependancyC C { get; set; }
public DependancyD D { get; set; }
}
public class Service1 : ServiceBase {}
The real question is does this highlight a wider design issue in the services?
Perhaps I am taking DI too far, but these are all genuine dependencies.
If so how do I code around this? If not is the proposed solution a valid way to achieve this goal?