A very minimal IoC container for learning how to invert control in Java?

I teach Java to a very young team. I have to enter them in IoC (Inversion Control). Starting with Spring is too complicated (they know a bit of java right now and a lot of jdbc under the hood).

I would like them to write a simple IoC consultant, but I need a very good example. I was thinking about a pico container, but I would like something very small (maximum 2-3 classes). http://picocontainer.codehaus.org/

Do you know something like that?

+4
source share
2 answers

Why not teach Weld SE? This is basically the same as Weld in the J2EE 6+ specification, but the initialization of the IOC container must be done explicitly in the SE version, and the additional complexity inherent in the web tiers can be ignored.

In addition, Weld is actually quite minimalistic, and you can use very minimal examples that do not depend on complex things, such as having a servlet container, and then fully process it to a complete multi-level J2EE application if you so wish.

It is also an IOC standard, and although it does not have Spring or Guice market penetration, you get it for free with J2EE 6 containers.

http://seamframework.org/Weld

Note. . A warning. Welding errors can sometimes be useless in my experience. Spring gives a much clearer picture of what is wrong when things REALLY explode.

+2
source

I would recommend starting with Google Guice. It is more compact than Spring and covers all the hallmarks of good IoC with minimal code.

You can probably pretty much use the Guice Getting Started tutorial for your training materials: https://code.google.com/p/google-guice/wiki/GettingStarted

0
source

Source: https://habr.com/ru/post/1484348/


All Articles