Note that there are some explanatory texts on larger screens.

plurals
  1. POIOC - Injection of multiple dependancies
    text
    copied!<p>Consider the below:</p> <pre><code>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) { ... } } </code></pre> <p>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.</p> <pre><code>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) { ... } } </code></pre> <p>Alternatively I could create a ServiceBase class.</p> <pre><code>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 {} </code></pre> <p>The real question is does this highlight a wider design issue in the services?</p> <p>Perhaps I am taking DI too far, but these are all genuine dependencies.</p> <p>If so how do I code around this? If not is the proposed solution a valid way to achieve this goal?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload