Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You write that</p> <blockquote> <p>the GadgetPresenter which creates the GadgetConfigPresenter[.]</p> </blockquote> <p>Instead of directly creating <code>GadgetConfigPresenter</code> instances, <code>GadgetPresenter</code> should <a href="https://stackoverflow.com/questions/1890341/how-to-set-up-ioc-when-a-key-class-needs-session-or-other-context-specific-varia/1890463#1890463">take a dependency on an Abstract Factory</a> that can create <code>GadgetConfigPresenter</code> instances for it. This pushes the inner dependencies of <code>GadgetConfigPresenter</code> to the factory.</p> <p>Using <strong>Constructor Injection</strong> all the way, your <strong>Poor Man's DI</strong> wiring should look something like this (apologies for the C# syntax):</p> <pre><code>var customerRepository = new CustomerRepository(/*...*/); var projectRepository = new ProjectRepository(/*...*/); var mandatorRepository = new MandatorRepository(/*...*/); var gadgetConfigPresenterFactory = new GadgetConfigPresenterFactory( customerRepository, projectRepository, mandatorRepository); var gadgetPresenter = new GadgetPresenter(gadgetConfigPresenterFactory); var dashboardPresenter = new DashboardPresenter(gadgetPresenter); var appPresenter = new AppPresenter(dashboardPresenter); </code></pre> <p>Notice how we <strong>break the dependency chain</strong> often, ensuring that the number of dependencies for each consumer never becomes too big.</p> <p>In principle, this means that you must create all the dependencies at boot time, unless you implement a <a href="http://blog.ploeh.dk/2010/01/20/RebuttalConstructorOverinjectionAntipattern.aspx" rel="nofollow noreferrer">lazy loading strategy</a>.</p> <p>Such things as managing lifetimes are exactly the sort of thing where a DI Container can be enormously helpful, but it's entirely possible to write an entire application by just <a href="https://stackoverflow.com/questions/2045904/dependency-inject-di-friendly-library/2047657#2047657">following DI patterns and principles</a>.</p> <p>All in all, though, I would still recommend a DI Container if at all possible.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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