I have a factory class that creates a couple of different types of class. The factory is registered with the container. What is the recommended way of creating the classes insid
This is something of a classic question.
Both of your solutions could be problematic if the number of different implementations increases, especially if the dependencies for each of the implementations have a lot of variance. You could end up with a constructor that takes 20 parameters.
My preferred implementation is to just have the factory class reference the container, and resolve the needed instance that way.
Some might argue that this is no better than the Service Locator anti-pattern, but I don't feel like there is a perfect solution to this problem, and doing it this way seems the most natural to me.