EduSpring Part 4: What is so terribly broken with Dependency Injection?
Move all the CS BS to the side. This stuff doesn't work in the real world. And it's because of things that could have (and probably should have) been fixed by uber-geeks 10+ years ago with fancy CompSci PhDs. And I'm talking about .Net specifically here, although I can throw the same stones at Java. Most (but not all) other languages have the same problems I'll get on my soapbox about here.
To do DI correctly, you have one of two options:
- Your class has dependencies on properties/internal fields that implement Interfaces
- Your class has dependencies on properties/internal fields that implement base classes
- Do you assume anything about the return value? It might return what you expect, or might return null. Or, it could throw an exception. Generally, experience with DI will teach you good defensive coding, but it does take work...
- Can the method handle null input values? If it errors, is it going to return null or throw an exception? If it throws, what kind of exception will it generate?
- Is the method you're calling going to muck with the object you pass in? If it does alter properties, is that a problem? What if you're not in control of the object, and the property this dependency decides it's OK to muck with throws an exception during the set operation?
Labels:
EduSpring
|
This entry was posted on 10:23 PM
and is filed under
EduSpring
.
You can follow any responses to this entry through
the RSS 2.0 feed.
You can leave a response,
or trackback from your own site.

0 comments:
Post a Comment