justmoon/constitute

Pass optional params to constructor?

Opened this issue · 1 comments

I want to use something like constitute(Person, user_id) for new Person(depA, depB, user_id), is it possible?

I too wonder this. When using constitue, is there any way of specifying parameters to the constructor that is NOT dependencies? If not, what is a good pattern to ensure that instances of classes are valid in the sense that they require some data that without a DI container would be sent in as arguments to the constructor?

EDIT: Reading through the docs and the code I guess one way would be to use the method factory and return a constructor that is defined within it's closure from that method. It does not feel like a very good way though.

I guess the problem is that I need to mock the constructor in some tests, and this tool is primarily used for IoC and hence instances of classes.