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

0
votes
1answer
54 views

MVVM with DI, view model location and shared service data

I have a couple of questions regarding MVVM view models. I have 3 view models in my scenario, which I have put together a shorter sample below. I was looking for a nice solution for 3 views working ...
0
votes
0answers
25 views

How to setup dependency injection framework in JavaScript

I'm creating a web page and would like to keep the UI and the JavaScript separate. To accomplish that I'd like to add event listeners after the UI elements have been created. I don't know if this is ...
1
vote
1answer
261 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 ...
1
vote
2answers
137 views

Opportunity cost of DIY DI?

Java here. I have always used Spring DI (for Spring projects) or Guice (for non-Spring projects) for dependency injection, and have always loved them. I recently took a job where they do 100% "DIY DI"...
1
vote
0answers
1k 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 ...
2
votes
1answer
81 views

Working with Dependency Injection using Factory pattern

I want to build a .jar that encapsulates a vendor api, so we can use our own objects as parameters to communicate with the api. I've read some articles and topics here in SO, but I still am a bit ...
-1
votes
0answers
23 views

Dependency Injection framework for TypeScript and JavaScript (es5) [migrated]

I've been looking for a DI framework that works well across TypeScript and pure JavaScript (es5). I've come across some implementations, such as Inversify and Angular's 2 DI. However, Inversify seems ...
0
votes
1answer
105 views

Inject several objects in C++ ctor

I'm looking for a good way to somehow dynamically inject several objects to main class and adjust its method by calls of these dependencies, e.g. ComponentClass1 { updateSmth1(); }; ...
3
votes
1answer
76 views

PHP OOP dependency injection - when is it o.k. to use the “new” statement

I was told to avoid "new" statements in classes or functions but rather create the objects from classes in the root of the programme (maybe with the use of a DI-container) and then inject the objects ...
0
votes
0answers
45 views

Code Duplication After Dependency Injection Instead Of Inheritance

I'm applying Dependency Injection instead of Inheritance. But now, I've the problem of code duplication. Main Controller final class PreferenceController implements PreferenceInterface { ...
15
votes
7answers
3k views

What is the “right” way to implement DI in .NET?

I'm looking to implement dependency injection in a relatively large application but have no experience in it. I studied the concept and a few implementations of IoC and dependency injectors available, ...
0
votes
1answer
51 views

MSDN - ServiceLocation Outdated Why? Alternatives?

I recently (1 month) start working in a project and as I was going through the code I saw an using Microsoft.Practices.ServiceLocation and as I searched for the documentation on that library is says: ...
4
votes
4answers
410 views

Are there any alternatives to dependency injection for stateless classes?

I am working on an application whereby I have designed classes to fit into several groups: Immutable: initialised through constructors, uses copy-and-swap idiom (inc. move), can deep copy (i.e. ...
7
votes
2answers
862 views

Does Serialization preclude the use of Dependency Injection?

Simple question: I understand that Serialization in C# requires default constructors. This would eliminate the possibility of using Constructor injected DI (which is generally the favored style of DI, ...
0
votes
0answers
24 views

Do you inject everything explicitly used in a module even if it is loaded in a “parent” module?

When you build a app modularized what do you inject into submodules? Only those things that are used there but not added at the top level, or do you inject everything that is explicitly used in that ...
8
votes
2answers
615 views

Who should initialize dependencies in a TDD application?

I'm trying to learn implementing TDD with mocking/fake objects. One of the questions I have is how to initialize a dependency in an application which implements TDD? An example from this article ...
3
votes
4answers
247 views

Class Library - How to communicate between objects that are not aware of each other?

I am trying to improve my programming skills and knowledge and I have been doing some reading about various design patterns and youtubing videos etc. One subject I thought was interesting was about ...
7
votes
4answers
2k views

Is dependency injection by hand a better alternative to composition and polymorphism?

First, I'm an entry level programmer; In fact, I'm finishing an A.S. degree with a final capstone project over the summer. In my new job, when there isn't some project for me to do (they're waiting ...
0
votes
2answers
97 views

Injecting a factory with multiple constructor parameters

Initially I needed only one queue to be created by the MessageQueueFactory: container.RegisterSingleton<IMessageQueueFactory>(() => { var uploadedWaybillsQueuePath = ConfigurationManager ...
3
votes
1answer
173 views

Dependency Injection & In-class Instantiation | Practical Limitations

Dependency Inversion is Good Inversion of dependency is good, it: Simplifies unit-testing Reduces coupling, allowing software components to be used interchangeably Keeps instantiation logic for a ...
9
votes
4answers
507 views

Dependency Inversion expands the API, results in unnecessary tests

This question has bothered me for a few days, and it feels like several practices contradict each other. Example Iteration 1 public class FooDao : IFooDao { private IFooConnection fooConnection;...
0
votes
1answer
100 views

Dependency injection multiple instances or only one InrequestScope

I'm trying to understand what happens with dependencies (Ninject) when a same Interface in injected in multiple classes. I am specifying InRequestScope for my bindings so as I understand there should ...
0
votes
1answer
85 views

Dependency Injection (DI) and Dependency Inversion Principle (DIP) for built-in functions and external libraries

Question I apologize if this question has already been posted. I tried searching but I couldn't find the answer. I often find myself trying to use DI and DIP where I need to open a file or a socket. ...
3
votes
3answers
147 views

Ambient dependency injection through static service locator

After some googling I found some debates about whether constructor injection or property/field injection is better, but there is yet another alternative that strikes me as more beneficial. In most ...
1
vote
1answer
67 views

How broad is the definition of “dependency injection”?

What is the "essence" of dependency injection? Is it the idea of dynamically swapping out/in core logical/structural aspects of a program at runtime? Traditionally, this is done in code via some DI ...
8
votes
4answers
788 views

How could dependency injection be integrated into the language? [closed]

I've been thinking a bit on how dependency injection could be better integrated directly into a C# like language. I've come up with a potential solution I'd like to hear your opinion on. I haven't ...
41
votes
11answers
3k views

Are so called “cross-cutting concerns” a valid excuse to break SOLID/DI/IoC?

My colleagues like to say "logging/caching/etc. is a cross-cutting concern" and then proceed using the corresponding singleton everywhere. Yet they love IoC and DI. Is it really a valid excuse to ...
5
votes
6answers
437 views

Dependency injection: should I use a framework?

I have recently worked on a Python project where we did dependency injection heavily (because we must in order for the app to be testable), but we didn't use any framework. At times it was a little ...
5
votes
4answers
224 views

Does anyone have a good DI registration pattern?

I've done this so many times but I never end up liking how my code turns out. I'm asking if anyone else has the same problems and can offer solutions or conventions that they've used to make cleaner ...
13
votes
3answers
554 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 ...
0
votes
1answer
68 views

Separate interfaces for dependency data providers?

I am attempting to refactor a component of a large project, which currently has a lot of dependencies to global state of the project environment. The goal (for my taste) is a "SOLID" architecture, ...
27
votes
11answers
2k views

Did a gradual shift in methodology of writing code affect system performance? And Should I care?

Lest you be confused by what's to follow, here is the driving idea behind the question: I always intended the question to be what it is. I may not have articulated it well originally. But intent ...
72
votes
5answers
21k views

When is it not appropriate to use the dependency injection pattern?

Since learning (and loving) automated testing I have found myself using the dependency injection pattern in almost every project. Is it always appropriate to use this pattern when working with ...
1
vote
1answer
166 views

Should composition happen no matter what?

I feel like I should be able to register all my components into the application composition root container no matter what the current state of the environment is, even in the case environment lacks ...
6
votes
2answers
502 views

How to avoid a crazy amount of interfaces in UI with dependency injection?

Problem I recently read a lot about Singletons being bad and how dependency injection (which I understand as "using interfaces") is better. When I implemented part of this with callbacks/interfaces/DI ...
0
votes
3answers
66 views

Value of dependency injection in MVC with skinny controllers

Dependency injection is often recommended in MVC projects because it's easy to implement with the pattern and adds a host of potential benefits. Indeed, it actually comes bundled with the default MVC ...
0
votes
1answer
57 views

Abstract Factories Nesting and DI - Is this acceptable?

I am still trying to get some experience with DI. Let me illustrate my situation and you can give me advice on whether I am using DI and Abstract Factory correctly. I need to create IModels at ...
14
votes
5answers
3k views

When to use interfaces (unit testing, IoC?)

I suspect I've made a schoolboy error here, and am looking for clarification. A lot of the classes in my solution (C#) - dare I say the majority - I've ended up writing a corresponding interface for. ...
12
votes
4answers
1k views

This way I'm writing this code is testable, but is there something wrong with it I'm missing?

I have an interface called IContext. For the purposes of this it doesn't really matter what's it does except the following: T GetService<T>(); What this method does is look at the current DI ...
7
votes
2answers
171 views

Gradually move codebase to dependency injection container

I have a large codebase with a lot of "anti-pattern" singletons, utility classes with static methods and classes creating their own dependencies using new keyword. It makes a code very difficult to ...
1
vote
3answers
107 views

SOLID principles and generating many objects from a file

The "D" in SOLID stands for dependency inversion. If I have for example, a Blacksmith class that depends on Hammer, I should create my Hammer externally and pass it to Blacksmith, rather than having ...
5
votes
2answers
4k views

What am I missing in my (mis)understanding of IoC/DI/Castle Windsor?

Okay, so here's how I understand IoC and DI in Web API to work when using Castle Windsor. Note, though, that my confidence that I understand it as I should, though, falls somewhere between my ...
2
votes
1answer
82 views

Constructor Injection vs Field Injection

I know this topic has been discussed a lot already so I don't want to get into which one is the "best way". I have been using field injection for a couple of years now but recently I discovered that ...
4
votes
2answers
127 views

Dependency Injection use in the “Clean Code” by R. Martin

In the Clean Code book by R.Martin, I have encountered the following method on p. 195: private void parseSchemaElement(String element) throws ArgsException { char elementId = element.charAt(0); ...
6
votes
3answers
200 views

How many injections is acceptable in one class when using dependency injection

I'm using Unity in C# for dependency injection, but the question should be applicable for any language and framework that is using dependency injection. I'm trying to follow the SOLID-principle and ...
5
votes
4answers
224 views

How does a Dependency Injection/IOC Container know which implementation to use?

When you use an IoC container, like so: var svc = IoC.Resolve<IShippingService>(); How does the IoC Container choose which implementation of IShippingService to instantiate? Further, if I am ...
2
votes
4answers
279 views

Reusing the logic in another repository in ASP.NET MVC repository pattern

I have an ASP.NET MVC4 web application, with EntityFramework for data access. In the application I have two repositories as follow (this is only an example not my real code): public class ...
4
votes
2answers
353 views

Are there any reasons not to use a DI framework on a standalone project?

While researching technologies for a new "pet project" I analyzed a few well-established project's source code and I noticed that they hardly use any dependency injection frameworks at all. For ...
3
votes
2answers
125 views

Repository pattern and Dependency Injection without an ORM

I want to implement the repository pattern in an old legacy project. I already did some research, and found that, without an ORM, it's completely acceptable to have methods like "GetBySpecialProperty"...
3
votes
0answers
70 views

Merits of DI, Abstract Factory implementation review

I'm writing a brand new system and trying to stay true to the SOLID principles, specifically Interfacing and Dependency Injection. We are sticking closely to the Microsoft stack so we are using C# ...