Thursday, July 28, 2016

Constructor Parameters known only at Runtime

it's assumed here that your Factory knows what the parameters for the constructors should be. If this is only known by the client of the Create method, then I would say the indirection isn't necessary and the client should construct the rule itself
http://stackoverflow.com/a/23765599

So, Factory Pattern may not be appropriate when the constructor parameters need to be provided by the client.

As for "DI abuse," see http://stackoverflow.com/a/1056229 on direct instantiation rather than injection of stateless services:
The abuse of DI leads to stateless objects which really should be stateful ... such code is by nature domain/use-case specific. In such a case ... it makes much more sense to have the [client] directly instantiate the business service class, passing data provided by the user through a constructor

No comments:

Post a Comment