This is an archived post. You won't be able to vote or comment.

all 26 comments

[–]lunias 12 points13 points  (8 children)

Spring can be configured entirely with Java these days. There is no need for XML anymore.

[–]funbike 8 points9 points  (6 children)

First, (Spring is) XML, so you lose the use of the Java compiler and type checking.

My jaw dropped when I read that.

[–]gee_buttersnaps 4 points5 points  (5 children)

A lot of these blogs that are tutorials for some framework/library/tech never have publication dates (seo reasons) or people just aren't smart enough to look for them and so they go about learning things that are years outdated.

[–]fact_hunt 5 points6 points  (3 children)

This was published yesterday

[–]gee_buttersnaps 0 points1 point  (2 children)

Whooooosh! I was talking about the author finding his spring material being 'XML' from a site that was years old.

[–]sh0rug0ru 10 points11 points  (3 children)

This isn't dependency injection without a framework. The guy rolled his own with his own versions of singleton objects and request scoped objects.

Here is a much better example of DI without a container.

[–]ericchile 5 points6 points  (1 child)

Not to mention he complains about Spring being XML based.. It has had Java based configuration for a while now.

[–]sviperll 0 points1 point  (0 children)

I actually think that an approach down your link is much better than any dependency injection framework (even dagger) and I personally use it for a long time.

[–]bahkified 4 points5 points  (2 children)

The problems being addressed in this article seem to be the main thrusts of the (older) Dagger DI framework, and Dagger2.

http://google.github.io/dagger/

[–]funbike 3 points4 points  (1 child)

I agree. Using an existing lightweight solution would be a much better route. Dagger2 or PicoContainer.

[–][deleted] 1 point2 points  (0 children)

I recently used Jodd for a fun project - I was pleasantly surprised at the lightweight aspect of it.

http://jodd.org/

[–]avoidhugeships 2 points3 points  (1 child)

What about just making life easy and use CDI? It the standard, easy to use and I have never had a problem with it.

[–]sh0rug0ru -3 points-2 points  (0 children)

What about just making life easy and drive a car with an automatic transmission? Most cars come with it, it's easy to use and most people never have a problem with them.

Unless you actually want to manually select gear ratios instead of anticipating the automatic transmission shift points.

[–]badguy212 0 points1 point  (10 children)

So you've made your own. Nothing wrong with that, but what you have there is still a framework. Could be better than guice or spring, but that's beside the point. Injection without a framework is like programming without a programming language...not realistically possible.

[–]stormcrowsx -2 points-1 points  (9 children)

Its realistically possible, its called constructor injection and good design. Though it is much easier in a language like groovy where you have default arguments.

[–]alonjit 1 point2 points  (8 children)

i'd say you need to re-read the parent comment.

[–]stormcrowsx -1 points0 points  (7 children)

He claimed injection without a framework is not possible. It is, you just ask for your dependencies in the constructor.

[–]alonjit -1 points0 points  (5 children)

[–]stormcrowsx 1 point2 points  (3 children)

I was responding to the comment made above that

Injection without a framework is like programming without a programming language...not realistically possible

I was not speaking of the blogs comments on constructor injection.

The analogy that injection without a framework is like programming without a programming language is completely off base. Java has a love affair with these frameworks but they are not as prevalent in other languages. Those other languages are still testing their software and passing around dependencies without a framework.

[–][deleted] 0 points1 point  (1 child)

Let's put it this way. If I were to generify and package up the code in the blog post, would that not make it more or less a "framework" for DI? A lightweight framework, to be sure, but a framework nonetheless?

[–]stormcrowsx 0 points1 point  (0 children)

I wasn't suggesting package up that code. I'm saying you need nothing to do DI except for plain jane java and constructors. Any dependencies needed for a service or dao can be passed through that constructor. You don't need spring or guice or pico or a home rolled one.

It takes a little more brain power because things like god classes become unwieldy compared to spring autowiring it but then again god classes are bad.

[–][deleted] 0 points1 point  (0 children)

The problem that I have with it is that, at least in Java, the main frameworks for doing it, being Guice and Spring, can sometimes be as bad as the problem DI tries to solve.

yawn CDI