Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Shot in the dark here, but could you move those parameters to the method instead?</p> <p>In other words:</p> <pre><code>public Check CreateCheck(bool doTranslateStubData, bool doAttachLogo) { //do the translation... } </code></pre> <p>Do those parameters <em>have</em> to be passed in via the constructor?</p> <p><em>(Note - if your response to this is "there are too many methods for that to be practical", then part of the problem may be that the abstraction is too coarse).</em></p> <hr> <p>Another option (it's really hard to say without understanding the domain model and injection patterns) would be to introduce a parameter object that is itself managed by the injector:</p> <pre><code>public interface ICheckConfiguration { bool AttachLogo { get; } bool TranslateStubData { get; } } </code></pre> <p>Then inject this with the constructor:</p> <pre><code>public CheckTranslator (IEmployeeService empSvc, IPaycheckService paySvc, ICheckConfiguration config) { // etc. } </code></pre> <p>This <em>should</em> be enough. You can then create a concrete <code>CheckConfiguration</code> class that takes those two <code>bool</code> properties in its constructor, and configure your container to create different instances of the parameter object (interface) based on a higher-level DI parameter.</p> <hr> <p>The last thing I think I should mention is that just because you're using DI doesn't mean that <em>everything</em> has to be managed by the container. It's not such a bad thing to create <code>CheckTranslator</code> objects in an ad-hoc fashion if there's only one kind of "translator". As long as the translator still depends on <em>abstractions</em>, which it does here, then maybe you shouldn't be injecting it at all, just let higher-level DI-enabled classes create them ad-hoc.</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.
 

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