DI, dependency-injection, is a design pattern where dependencies (instances of objects, properties) of a component are set through the constructor(s), methods or fields (properties)

learn more… | top users | synonyms

-3
votes
0answers
27 views

How to implement dependency injection in EJB 2.x [closed]

I want to add dependency injection into big EJB 2.1 application that runs on WebLogic 11 server with Java 6. My question is, how to do it in the best way? Do you have any hints? Should I implement ...
3
votes
2answers
158 views

IoC as service locator

I have been wondering for quite some time on some issues while using dependency injection: In a layered application, I normally inject repositories into the application service using constructor ...
1
vote
3answers
169 views

Why does dependency injection encourage collaboration to be exposed via constructors?

The general approach to DI that I see in answers like So Singletons are bad, then what? encourages business objects that collaborate with other objects to (a) not directly create those instances and ...
1
vote
1answer
125 views

C# Dependency Injection Placement

This is my first time using Unity so bear with me for a moment. I have a sample Visual Studio 2012 project with 4 projects (but only two of these projects will be used with Unity). This is the ...
0
votes
1answer
189 views

Pooling (Singleton) Objects Against Connection Pools

Given the following scenario A canned enterprise application that maintains its own connection pool A homegrown client application to the enterprise app. This app is built using Spring framework, ...
1
vote
1answer
325 views

Organising data access for dependency injection

In our company we have a relatively long history of database backed applications, but have only just begun experimenting with dependency injection. I am looking for advice about how to convert our ...
1
vote
2answers
306 views

Where should I put bindings for dependency injection?

I'm new to dependency injection and though I've really liked it so far, I'm not sure where bindings should go. I'm using Guice in Java, so some of what I say might be specific to just Guice. As I see ...
4
votes
2answers
160 views

Reducing dependency cycles and reducing coupling

I'm trying to learn how to produce quality object-oriented code and have been studying concepts like SOLID. I'm currently working on an entity-component-process system for a small game engine. ...
0
votes
1answer
291 views

How should dependencies be managed across a modular application?

Let's say that we have a structure like this: Application -- Modules --Module1 -- Controller -- PublicHelper --Module2 -- Controller ...
0
votes
0answers
59 views

Am I following a good design thought process? Is the Abp framework overkill?

As I finish one project and start another, I have a small time window to come up with an architecture for the new. I am coming from the following design: Web applicationReceives domain models & ...
0
votes
1answer
44 views

Value Object: static factory or assisted injection?

First let assume that everybody agree that there is nothing wrong with injecting some value object into injectable object such as service. Indeed, a service can get another service injected, but could ...
1
vote
2answers
204 views

when using dependency injection, should I always pass an interface

When using depending injection, you generally pass everything around as an interface (perhaps with the exception of primitives and strings). That allows you to easily chance the behavior, without ...
0
votes
0answers
23 views

Data serialization architecture, injection on construction vs. on function call

I am creating a data serialization/deserialization mechanism for essentially a persistent storage object. Due to the variety of systems this mechanism could run on, there needs to be a a variable ...
13
votes
3answers
624 views

I get dependency injection, but can someone help me understand the need for an IoC container?

I apologize if this seems like yet another repeat of the question, but every time I find an article regarding the topic, it mostly just talks about what DI is. So, I get DI, but I'm trying to ...
1
vote
2answers
119 views

Why do IoC containers provide public Resolve method(s)?

In my opinion it just inverses the inversion and could make new users (including myself) make incorrect assumptions about using IoC containers. It can be used for the Service Locator (anti-)pattern ...
5
votes
4answers
424 views

What complexity do DI frameworks add? [closed]

The currently most upvoted answer to a very recent question states that DI containers are an "enterprise software" pattern, used when the object graph is very large and complex. I suspect that 95% ...
6
votes
4answers
709 views

Acceptable placement of the composition root using dependency injection and inversion of control containers

I've read in several sources including Mark Seemann's 'Ploeh' blog about how the appropriate placement of the composition root of an IoC container is as close as possible to the entry point of an ...
1
vote
1answer
130 views

Should the Presenter depend on the View or the vice versa?

So far, I have used the MVP architecture pattern a few times. Every now and then, I wonder whether my Presenter should depend on my View or vice versa, that is the View depends on my Presenter. NOTE ...
17
votes
6answers
6k views

Dependency injection ; good practices to reduce boilerplate code

I have a simple question, and I'm not even sure it has an answer but let's try. I'm coding in C++, and using dependancy injection to avoid global state. This works quite well, and I don't run in ...
1
vote
1answer
59 views

Ninject/DI: How to correctly pass initialisation data to injected type at runtime

I have the following two classes: public class StoreService : IStoreService { private IEmailService _emailService; public StoreService(IEmailService emailService) { _emailService ...
2
votes
2answers
170 views

Dependency Injection: where to store dependencies used by only one method?

I am developing a project integrated with Dependency Injection (just for reference, I'm using Unity). The problem is that I have some Manager classes with several methods and in many cases I have ...
4
votes
5answers
397 views

Questioning one of the arguments for dependency injection: Why is creating an object graph hard?

Dependency injection frameworks like Google Guice give the following motivation for their usage (source): To construct an object, you first build its dependencies. But to build each dependency, ...
1
vote
2answers
90 views

How best to construct our test subjects in unit tests?

Some of our business logic classes require quite a few dependencies (in our case 7-10). As such when we come to unit test these the creation become quite complex. In most tests these dependencies are ...
1
vote
2answers
148 views

How to handle “circular dependency” in dependency injection

The title says "Circular Dependency", but it is not the correct wording, because to me the design seems solid. However, consider the following scenario, where the blue parts are given from external ...
5
votes
1answer
339 views

Decoupling when constructors have non-contractual parameters

By non-contractual parameters, I mean parameters that are not interfaces or service dependencies, something like class Person(string name). I am writing a webpage scraping application, and so far ...
7
votes
3answers
412 views

Recommendations on integrating DI/IoC container into an existing application

I am now faced with integrating an inversion of control (IoC) container into an existing application, and I'm looking for some recommendations on how that can most easily be accomplished with the ...
0
votes
0answers
130 views

When to use packages or Repositories in Laravel?

I'm a Laravel (PHP) developer, and new with DI, Packages (workbench) and Repositories (Pattern). I want to know about the best concept/methodology for a more flexible design; ie. the project can grow ...
2
votes
1answer
52 views

Are the required parameters of a function called dependencies?

I'm studying dependency injection and I want to know if required function parameters can be considered dependencies. I'd just like to make sure before I go around referring to them dependencies and ...
1
vote
2answers
88 views

How should one implement the dependency-injection for a geocoding client that aggregates different coordinate provider implementations?

I am new to DI and I would like to know how DI might be used to help resolve this problem. If I have an ILatLongLocation which implements a Latitude and Longitude, then given two of these I can ...
0
votes
0answers
105 views

Save database changes in service layer or controller mvc .net

I have recently been using a service layer to abstract away alot of the business logic of my application. However I've come into an issue where I'm not sure what is best practice on doing the actual ...
0
votes
1answer
113 views

How can I use guice to replace code dependent on service locator implementation?

Consider I have a service called FileSystem, and that this FileSystem is used by various classes throughout the application. Typically, the service is acquired via some static class method ...
3
votes
1answer
138 views

Showing a View from another View in MVP

This question is regarding MVP triads. Lets say I have two triads and first one has View1, Mode1 and Presenter1. Second triad has View2, Model2 and Presenter2. Now what I trying to do is, I just want ...
11
votes
3answers
390 views

Do dependency injection frameworks pose a dependency risk?

I have been refactoring an existing system to use dependency injection, and that work has been going smoothly. After a while I noticed that a large number of in-house libraries became dependent upon ...
-5
votes
1answer
3k views

What are Dependency Injections and why are they useful? [closed]

I have heard of ninject and I have to build a lot of apps that have to integrate with other tools. SO i was wondering what this was and how it is used.
30
votes
3answers
3k views

How does dependecy injection increase coupling?

On the Wikipedia page on dependency injection, the disadvantages section tells us this: Dependency injection increases coupling by requiring the user of a subsystem to provide for the needs of ...
1
vote
1answer
97 views

How to properly handle conditional dependencies in a factory?

Let's say you have a string $action run-time, that specifies which type of $object needs to be created: $dbobject, $memcacheobject, $fileobject, $xmlobject, etc. Assume also, that creation of an ...
1
vote
3answers
171 views

Passing a dependency to a controller class

I'm looking for an approach to the following problem: I have a reusable library. It contains a controller class, in the MVC sense. Let's say it's called UserAdministrationController, and it's for ...
2
votes
1answer
130 views

How to handle passing multiple dependencies in a module hierarchy

So I have my application consisting of a number of modules in a module hierarchy. Furthermore let's also assume each module is a class and we have a tree of classes where the classes at the top are ...
0
votes
1answer
189 views

Applying DDD to a simple app with a configuration twist

I’m using the light-weight PHP Fat-Free Framework as a base to form a simple MVC based app with DDD philosophy for the Model layer. I’m aware that DDD is most suitable or enterprise solutions and that ...
3
votes
3answers
134 views

Using 2 Constructors: one that injects dependencies and one that instantiates them

I started using TDD for the first time on a project I started recently. I have a few objects with dependencies and structures that look something like this: public class MyClass { private ...
4
votes
2answers
82 views

How to extend Constructor Injection?

Suppose I have MyClass with a very simple dependency. It uses constructor injection. public class MyClass : IMyClass { private IA A; public MyClass(IA a) { A = a; } } This ...
5
votes
1answer
442 views

To Repository Or Not To Repository

When I first learnt about Domain Driven Design, I was also introduced to the repository and unit of work patterns that once seemed to be top notch for the cool kids that threw SQL queries like ...
1
vote
2answers
92 views

Dependency injection for request variables in a web application

I'm working a PHP 5.5/MySQL web application. If a class depends partly on some global GET and POST variables for its members, should I just refer to them directly from within the class, or should I ...
0
votes
0answers
422 views

Spring bean injection into a hibernate validator constraint

I have a controller method like listed below whose argument is annotated with @Valid to validate PasswordChange object using a Hibernate validator @Constraint. Both PasswordChange and a sample ...
9
votes
3answers
3k views

Which classes should be autowired by Spring (when to use dependency injection)?

I have been using Dependency Injection in Spring for some time now, and I understand how it works and what are some pros and cons of using it. However, when I'm creating a new class I often wonder - ...
0
votes
1answer
73 views

How to design a domain entity that uses a dependency to manage a state field?

I'm new to DDD and IOC/DI and I'm having some trouble figuring out how to design an entity that needs to use a state pattern to manage its status. As the transitions are somewhat complicated, I'm ...
1
vote
0answers
118 views

State Pattern Code for embedded device - Dependency Injection of Device Objects in Context and State Classes

I'm wrestling with some code and I think I've finally gotten some state pattern code working with my events. I've got a simplified system that will work like this: This is my first go with State ...
1
vote
2answers
160 views

Dealing with an often occuring dependency that is not related to the class

I'm using view classes for my templating. These view classes often require the Routing class to get URI's from other pages. You could actually say that the Routing should be available to every view ...
6
votes
3answers
221 views

Dependency Injection vs Mixing Levels of Abstraction

I've been reading Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin. One point he makes: G34 Functions should descend only one level of abstraction However, I'm ...
2
votes
2answers
219 views

Injecting dependencies (DI) in c++ applications

I am playing with dependency injection, but i am not sure I am doing it right. Especially, I am not sure what should be the correct way to build classes with injected dependencies. Say I have a class ...