Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two routes you can take, depending on your needs.</p> <p><strong>1. Wire the UI directly to your concrete classes</strong></p> <p>This is the simplest option, but many times perfectly acceptable. While you may have a Domain Model with lots of interfaces and use of DI, the UI constitutes the Composition Root of the object graphs, and you could simply wire up your concrete class here, including your requrired port number parameter.</p> <p>The upside is that this approach is simple and easy to understand and implement.</p> <p>The downside is that you get less flexibility. You will not be able to arbitrarily replace one implementation with another (but then again, you may not need that flexibility).</p> <p>Even with the UI locked to a concrete implementation, this doesn't mean that the Domain Model itself wouldn't be reusable in <em>other applications</em>.</p> <p><strong>2. Add an Abstract Factory</strong></p> <p>The other option is to add another layer of indirection. Instead of having your UI create the class directly, it could use an Abstract Factory to create the instance.</p> <p>The factory's Create method could take the port number as an input, so this abstraction belongs best in a UI sub-layer.</p> <pre><code>public abstract class MyFactory { public abstract IMyInterface Create(int portNumber); } </code></pre> <p>You could then have your DI container wire up an implementation of this factory that uses the port number and passes it as a constructor argument to your real implementation. Other factory implementations may simply ignore the parameter.</p> <p>The advantage of this approach is that you don't pollute your API (or your concrete implementations), and you still have the flexibility that programming to interfaces give you.</p> <p>The disadvantage is that it adds yet another layer of indirection.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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