I've been reading about Spring and although it's claimed to be a less complex alternative to EJB, I'm having a hard time wrapping my head around it. Is there a more minimal way of achieving Dependency Injection than adopting the Spring approach?
Why not just do it without a framework ?
Ask what your class depends on, and then inject those objects via (say) the constructor.
Some hints:
e.g. simply create a class with a constructor thus:
public TradeSaver(final ITradeValidator validator, final ITradeDatabase db);
(where both parameters are interfaces) and you can then inject the core components that your TradeSaver
depends on (validation and database saving), with the option of providing different implementations for testing, different deployments etc.
Google Guice is a very minimalist DI framework.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With