Home » Tag Archives: Dependency Injection

Tag Archives: Dependency Injection

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 »

Spring vs Guice: The one critical difference that matters

google-logo

Spring objects are recognized based on their names It doesn’t matter whether you use XML or Java config, a Spring scope is roughly like a Map<String, Object> structure. This means that you cannot have two objects with the same name. Why is this a bad thing? If you have a large application with lots of @Configuration classes or XML files, ...

Read More »

Spring 3: Type safe dependency injection

spring-interview-questions-answers

Before jumping to Type Safe Dependency Injection from Spring, I would like to to discuss the way we have been doing it earlier. We have been using dependency injection by type with the help of Autowired annotation from Spring. Something like this would inject the spring bean. @Autowired private StudentDao studentDao; // Autowires by type. Injects the instance whose type ...

Read More »
Do you want to know how to develop your skillset and become a ...

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!
Get ready to Rock!
To download the books, please verify your email address by following the instructions found on the email we just sent you.

THANK YOU!

Close