Skip to main content
2 of 2
added 325 characters in body
Euphoric
  • 37.8k
  • 6
  • 81
  • 117

Your solution is exactly how this problem should be solved. And it truly is called a Factory. Yes, things get somehow messy when lots of dependencies are involved.

Some more advanced IoC containers, like Unity, can create these kind of factories automagically. Well, according to Unity auto-factory with params , only Autofac can really do that out-of-the box. While Unity can do it, the setup seems to be not much different from defining your own class in terms of amount of code and complexity.

Euphoric
  • 37.8k
  • 6
  • 81
  • 117