constitute icon indicating copy to clipboard operation
constitute copied to clipboard

Pass optional params to constructor?

Open aksonov opened this issue 9 years ago • 1 comments

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

aksonov avatar May 29 '16 08:05 aksonov

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.

tregusti avatar Jul 01 '16 12:07 tregusti