Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [ioc-containers]

The tag has no usage guidance.

1
vote
2answers
110 views

Does an IoC-Container violate the Open/Closed-Principle?

Right now I construct all objects of my application in the root class manually. Since it is getting ugly now, I want to switch to an IoC-Container like Autofac. Now I have to register each interface ...
0
votes
1answer
89 views

How to deal with complex dependency graph in IOC?

I have several apps witch build from one code base (using common modules). And my question: how to write composition root in this case? Let's imagine simple dependency graph: ClassBase --> ...
1
vote
0answers
93 views

IoC - Should I use child containers to create scoped dependencies?

I have a number of command handlers defined for doing work against databases on various servers in our network. I am wondering if I should design each command to pass the following information in the ...
2
votes
3answers
728 views

Is there a need for an IoC container in TDD unit tests?

While I do see the benefits of IoC containers (as I've used them a fair bit), I don't see how they can be incorporated within TDD unit tests (note, I'm only interested in unit tests here, not ...
16
votes
2answers
1k views

Is there evidence that the use of dependency injection improves outcomes in software engineering?

Notwithstanding its popularity, is there any empirical evidence that shows that Dependency Injection (and/or using a DI container) helps with, say, reducing bug counts, improving maintainability, or ...
1
vote
2answers
72 views

IoC configurations - one file/assembly in solution or one file per executing assembly?

We're wondering what the best practise for registering types in a IoC-Container is. What would be arguments for and against the following principles: Principle 1: Only one Assembly my.project....
4
votes
4answers
573 views

How to pass data between objects when an IoC container is being used?

I'm working with a project that our architect has decided to use dependency injection for almost everything. We use an IoC container. One of the main issues that I keep coming across when using this ...
0
votes
1answer
212 views

IOC principle - Servlet container implementation

IOC principle can be implemented, using either: Dependency Injection Service locator pattern This article also supports these two approaches for implementing IOC principle. Spring IOC container is ...
1
vote
4answers
828 views

Image processing - Service locator pattern & Container of dependencies

As per wiki, A dependency is an object that can be used (as a service). here is the OOP paradigm using C syntax that address 4 roles, shown below. 1) interface (handlers.h) typedef struct { ...
2
votes
2answers
452 views

How to use Dependency-injection Containers correctly when they hide dependencies from outer classes?

From Zend Docs there is this example of how to use Zend\Di, which is a dependency injection container of Zend Framework: // inside a bootstrap somewhere $di = new Zend\Di\Di(); // inside each ...
0
votes
2answers
447 views

How to create a factory method

Say I have a Business class called person: public class Student { } Say I want to create a factory method for this Student class - something like this: public Student getStudent(string studentType) ...
5
votes
3answers
677 views

DependencyInjection - Constructor over-injection smell vs service locator - where is the proper approach?

I am trying to improve my MVC projects and I read a few articles about DI, IoC containers, Constructor Injection and Service locators. I wanted to go with Ninject to help with the dependencies, but ...
6
votes
3answers
436 views

How do I support per-method-call instantiation without referencing the IoC container outside the composition root?

I read with interest this article which states: A DI Container should only be referenced from the Composition Root. All other modules should have no reference to the container. This means that ...
2
votes
2answers
884 views

Replace ASP.NET Core's DI container with external container

I'm using ASP.NET Core's builtin DI container. It's missing some features I need, so I need to use a third-party container. The top ones on Nuget are Autofac and StructureMap. SimpleInjector is ...
4
votes
1answer
191 views

Does an IoC Container affect the design of an application using Dependency Injection?

Is it safe to say that a Container is the "program" or mechanism that manages IoC via DI, but it doesn't really change your initial design of DI to accomplish loose coupling? In other words, if I ...
8
votes
3answers
472 views

DI/IoC container vs factories: Where do I configure my application and why?

I am trying to figure out when to use the DIC/IoC registry for configuring my software and when to use factories, along with the reasoning behind either approach. I am using StructureMap as my DI ...
2
votes
2answers
322 views

IoC Framework vs. DI Layer

Say we have a class structure like the following: // implementation.ts export class A implements IA { constructor(private b: IB) {} } export class B implements IB { constructor(private c: IC) ...
6
votes
4answers
930 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 ...
3
votes
2answers
567 views

Best practice in helper/util methods: IoC container or static methods?

So I'm developing an application which is using an IoC container. Now I need some helper methods for array manipulation like set, get, etc. I see two possible ways to go: Using a class with static ...
0
votes
2answers
280 views

IoC container with lifetime attribute [closed]

Which ioc frameworks for .net can use concrete type attribute to choose it's lifetime? Here is a simple example public interface IService {} [Singleton] public class ServiceImplA : IService {} [...
0
votes
3answers
274 views

How should I refactor a singleton (to be used by a container) when the refactored class requires initialization and takes a dependency?

I'm refactoring an old app to use dependency injection.n I'm pretty new to DI. I have a class that used to be a singleton. I'm refactoring it into a non-singleton class and using the container to ...
2
votes
1answer
383 views

Transient life time and constructor injection

I'm working on a little light weight Dependency resolver found here https://github.com/AndersMalmgren/DuoCode.SimpleInjector Currently if you do var instance = container.Get<Foo>(); You get ...
4
votes
3answers
371 views

IoC invalidation

I have a bunch of services that get registered as singletons by my IoC container on startup, all of these services have a constructor which takes in a connection string which is used by the underlying ...
15
votes
3answers
2k 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
542 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 ...
0
votes
1answer
663 views

Practical Use of Depency Injection (IoC) Container

I am creating a MVC-ish framework in PHP. I am trying to implement a DI Container to allow the creation of controller objects (among others). My MVC framework is pretty typical. Each module (or ...
5
votes
3answers
1k views

Breaking the “ubiquitous language” by having an IoC Container in Domain Model?

I am a bit new to DDD and bear with me if my understanding seems way off. My question is about Udi's solution to domain events, particularly the class DomainEvents (see code below) An excerpt from ...
1
vote
1answer
386 views

it is a good approach to implement dependency injection in a desktop app?

Well, the thing is that I am just about to create a Desktop App (with .NET windows forms) And now I just wonder if it would be really a wise choise to use any IoC (StructureMap,Ninject,Spring .Net), ...
-2
votes
2answers
1k views

Generics vs IoC [closed]

One of the "Service Locator" pattern drawbacks is that a caller can be misleaded about dependencies of a callee. Ok, but what if I put dependencies as generic parameters at a class level: class Node&...
93
votes
7answers
45k views

Why is Inversion of Control named that way?

The words invert or control are not used at all to define Inversion of Control in the definitions that I've seen. Definitions Wikipedia inversion of control (IoC) is a programming technique, ...
3
votes
1answer
463 views

Is it a bad design to specify default bindings when using Inversion of Control (IOC) containers and dependency injection (DI)?

I'm using Ninject, but this is not a Ninject-specific question. I'm wondering if the advanced and flexible capabilities of the IoC container are giving me enough rope to hang myself with a bad ...
8
votes
4answers
2k views

Acceptable placement of the composition root using dependency injection (DI) and inversion of control (IoC) 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 ...
7
votes
3answers
549 views

IOC and stateless services. Short-lived or single-instance?

Given a garbage-collected framework, when using an IOC container to inject purely stateless services, is it generally better to use the container's single-instance lifespan or to recreate the object ...
16
votes
1answer
7k views

Dependency Injection/IoC container practices when writing frameworks

I've used various IoC containers (Castle.Windsor, Autofac, MEF, etc) for .Net in a number of projects. I have found they tend to be frequently abused and encourage a number of bad practices. Are ...
1
vote
2answers
396 views

Trying to grasp the idea of DI/Unity and possibly apply it to our simple application

Our app basically is a few forms that are filled out by people.. Then these forms are validated and reviewed and reports are created.. So I was thinking about DI and messing with a simple example of ...
7
votes
3answers
2k views

Inversion of Control in ASP.NET MVC [closed]

I was going to refactor my ASP.NET MVC application and inject some IoC. Last time I was using IoC, Unity was all the rage, but I hated it. It was difficult to setup and had very nondescript errors. ...
21
votes
6answers
2k views

Should the usage of DI/IoC remove all occurrences of the “new” keyword?

Should the usage of Dependency Injection and an Inversion of Control container remove all occurrences of the "new" keyword from your code? In other words, should every object/dependency, no matter ...
-1
votes
1answer
317 views

PocoCapsule project status

Does anybody know the status of this C++ Inversion of Control Container? Any alternative?
3
votes
1answer
2k views

Better to inject IoC container or use a Service Locator pattern? [duplicate]

I have an IoC container (If you want a specific one to look at, it's very similar to Unity) and I'm working on how I want to integrate it into my application. My overall goal for this exercise is to ...
10
votes
4answers
1k 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 ...
5
votes
1answer
774 views

Have any of you used MEF to configure Castle Windsor

I am thinking of using MEF to manage the fluent interface on Castle Windsor. Allowing for me to swap out different sections of the system for test and production. Has anyone done this if so how well ...
17
votes
3answers
3k views

Sell me on IoC containers, please

I've seen several recommend use of IoC containers in code. The motivation is simple. Take the following dependency injected code: class UnitUnderTest { std::auto_ptr<Dependency> d_; public: ...