dry-rb / dry-auto_inject

Container-agnostic constructor injection mixin

Home Page:https://dry-rb.org/gems/dry-auto_inject/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make kwargs injection strategy the default

timriley opened this issue · comments

I'd like to help dry-auto_inject be as usable as possible for people, and I think making the kwargs injection strategy the default would help a lot for this.

Positional args are a bit magical and complex, and it the manual replacement of specific dependencies feels really awkward (e.g. MyThing.new(nil, nil, my_dep)). Keyword arguments make this feel a lot more natural (MyThing.new(my_dep: dep)) and will make for more flexible objects in general.

I don't think we should rely on each user coming this same conclusion and then having to make the decision themselves to switch strategies; I think kwargs should be the default, and users can then switch away from this in cases where they have compelling reasons.

This is a simple change to make, and it feels like it would nice to include in the upcoming release, given we have a lot of other nice improvements to share at the same time. What do you think?

This is a good idea, it'll be most common usage I think. In fact we might as well consider deprecating positioned args in the longer term. Time will tell.