top | item 23505002

(no title)

modarts | 5 years ago

By declaring dependencies in code (usually with annotations or decorators)

discuss

order

m3h|5 years ago

What do you do when you want to choose the implementation for dependencies and optionally configure them at runtime?

I think that's why most of the popular dependency injection frameworks I see support configuration through XML or JSON.

HereBeBeasties|5 years ago

Firstly, you barely ever do.

Secondly, unless you're selling compiled software for others to configure, there really is no difference between config in config files and config in code, except that the former does not let you build such meaningful and useful abstractions. You're presumably delivering it all into production via CI/CD anyway, so what difference editing a config file vs. some actual source code, besides the lack of real type safety and IDE assistance?

Pulumi have figured this out.

(And I suspect that if your end users need to configure your software's use of Spring's Dependency Injection in XML config then you are probably doing it wrong.)

atraac|5 years ago

Then you also do that in code? I don't see how that would differ. If your container doesn't support that, you can always just make a Factory for it.