Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's hard to say without seeing some code, but you may want to look into implementing a Repository Pattern. The Repository implementation would be responsible for retrieving the data that the factory then used to build its object(s). You could inject the repository interface into your factory:</p> <pre><code>public class ModelParameterFactory : IModelParameterFactory { private readonly IModelParameterRepository Repository; public ModelParameterFactory(IModelParameterRepository repository) { Repository = repository; } ...interface methods use the injected repository... } </code></pre> <p>Then you would have, say a DatabaseModelParameterRepository and a FileModelParameterRepository. But I'm guessing you also have logic around which of those you would need to inject, so that calls for another factory:</p> <pre><code>public class ModelParameterRepositoryFactory : IModelParameterRepositoryFactory { public ModelParameterRepositoryFactory(...inputs needed to determine which repository to use...) { ...assign... } ...determine which repository is required and return it... } </code></pre> <p>At this point, it might make more sense to inject IModelParameterRepositoryFactory into the ModelParameterFactory, rather than inject the IModelParameterRepository. </p> <pre><code>public class ModelParameterFactory : IModelParameterFactory { private readonly IModelParameterRepositoryFactory RepositoryFactory; public ModelParameterFactory(IModelParameterRepositoryFactory repositoryFactory) { RepositoryFactory = repositoryFactory; } ...interface methods get repository from the factory... } </code></pre> <p>Whether you use a DI container or not, all logic regarding which repository to use and which factory to use are now moved into the relevant factory implementations, as opposed to the calling code or DI configuration.</p> <p>While not terribly complex, this design nonetheless does give me pause to wonder whether your ModelParameterFactory and ModelParameters are too generic. You might benefit from teasing them into separate, more specific classes. The result would be a simpler and more expressive design. The above should work for you if that is not the case, however.</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. This table or related slice is empty.
    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