3 ms·
Can't see where this 'magic' comes from. IoC frameworks are not rocket science. Everything is very-well documented and pretty straightforward. > dependency inj
by kovrik 8y ago
Can't see where this 'magic' comes from. IoC frameworks are not rocket science. Everything is very-well documented and pretty straightforward.
> dependency injection frameworks are an unnecessary and overcomplicated way of achieving it.
But why?
I don't want to write my own DI framework for each new project.
I'd better add one dependency, put some @Autowired (and other well-documented) annotations and continue writing business logic.
Aforementioned 'magic' is basically creating a context, scanning all annotations, registering beans, instantiating them (calling constructors), then injecting them.
- drdeca 8y agoI wouldn't mind having things be created through autowiring and the like, if it didn't make it harder to make the things explicitly, without autowiring. Ideally, making something automated should not make it harder to do the same thing manually.
- lmm 8y agoModern Java does fix that much. If you look at the `Sample` class from the example, it's a normal class that you can instantiate the normal way (passing its dependencies into its constructor) and ignore the annotations on, unlike the bad old days of afterPropertiesSet().
- smolder 8y agoAs someone who recently worked on a spring project for the first time, it's pretty clear what magic we're talking about. I can't look at the code and know what the application does without first learning the meaning of a ton of different annotations and the behaviors connected with them. Annotations and the associated code are complex. Now that I understand what they all do, it's easy to reason about the app, but when I run it my mental model is still: 1. I launch the app 2. Spring does a bunch of stuff I only vaguely understand and can't understand from looking at the code 3. My actual code starts running On top of that, all the spring stuff makes the memory footprint and startup time awful.