Home » Tag Archives: Dependency Injection

Tag Archives: Dependency Injection

Your DI framework is killing your code

software-development-2-logo

I read a really interesting post recently looking at the difference between typical OO code and a more functional style. There’s a lot to be said for the functional style of coding, even in OO languages like Java and C#. The biggest downside I find is always one of code organisation: OO gives you a discoverable way of organising large amounts of ...

Read More »

Is Getter DI A Good Idea?

java-logo

Sometimes, you may hear about dependency injection done via a getter method, which subclasses override or mock frameworks fake for testing. It allows the class to have a set dependency that is actually hard coded, but can be “injected” if need be. I’ve written before about the idea of what I will call “firm-coded” dependencies from now on. I didn’t ...

Read More »

In today’s post-OO world, is dependency injection still relevant?

software-development-2-logo

It’s 2015. Most of the new popular languages are more or less functional. The old ones, like Java, gain functional programming elements. In Scala, people are increasingly leaning towards the pure side, using more FP and less OO. So – Dependency Injection? Really? You could say that DI is just using (constructor) parameters. I’m saying that as well in my ...

Read More »

Dependency Injection – Field vs Constructor vs Method

java-logo

Hi, today I would like to discuss in short different ways of injecting dependencies into your classes. In general you have the following three options for injection directly into fields/attributes via explicit setter methods via explicit constructor parameters     Field injection This type of injection instruments some kind of reflection mechanism for injecting the required dependencies into the class. While this injection ...

Read More »

Dependency injection pitfalls in Spring

spring-interview-questions-answers

There are three injection variants in Spring framework: Setter-based injection Constructor-based injection Field-based injection Each of those mechanisms has advantages and disadvantages and there is not only one right approach. For example field injection:      

Read More »

Injecting domain objects instead of infrastructure components

java-interview-questions-answers

Dependency Injection is a widely used software design pattern in Java (and many other programming languages) that is used to achieve Inversion of Control. It promotes reusability, testability, maintainability and helps building loosely coupled components. Dependency Injection is the de facto standard to wire Java objects together, these days. Various Java Frameworks like Spring or Guice can help implementing Dependency ...

Read More »

DI Containers are Code Polluters

java-interview-questions-answers

While dependency injection (aka, “DI”) is a natural technique of composing objects in OOP (known long before the term was introduced by Martin Fowler), Spring IoC, Google Guice, Java EE6 CDI, Dagger and other DI frameworks turn it into an anti-pattern. I’m not going to discuss obvious arguments against “setter injections” (like in Spring IoC) and “field injections” (like in ...

Read More »

Dependency Injection Options for Java

java-interview-questions-answers

I wanted to take some time to put together a summary of some popular dependency injection (DI) frameworks for Java. This is a high-level overview of what’s available. First off, what is dependency injection? “Dependency injection is a software design pattern that allows the removal of hard-coded dependencies and makes it possible to change them, whether at run-time or compile-time.” ...

Read More »

Dependency injection with Scala macros: auto-wiring

scala-logo

You can look at dependency injection as a fancy name for passing parameters to a function (or constructor arguments to a constructor). However usually, DI containers do much more than that. Among other things, one very nice feature is auto-wiring: instantiating the right objects with the right arguments. Most popular frameworks (Spring, Guice, CDI/Weld) accomplish this task at runtime using ...

Read More »

How I explained Dependency Injection to My Team

java-interview-questions-answers

Recently our company started developing a new java based web application and after some evaluation process we decided to use Spring. But many of the team members are not aware of Spring and Dependency Injection principles. So I was asked to give a crash course on what is Dependency Injection and basics on Spring. Instead of telling all the theory ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Spring Interview QnA
  • Multithreading & Concurrency QnA
  • JPA Minibook
  • JVM Troubleshooting Guide
  • Advanced Java
  • Java Interview QnA
  • Java Design Patterns