Skip to main content

Questions tagged [ioc-containers]

Filter by
Sorted by
Tagged with
3 votes
4 answers
289 views

Please explain the "swapable dependency" arguments for IOC containers

I get that IOC containers can be useful to help break dependencies and allow you to test a class in isolation. I don't wish to focus on that right now, instead, I'm trying to understand some of the ...
Scotty Jamison's user avatar
0 votes
6 answers
1k views

If it is a bad practice to use an interface if only one class will implement it, what is the purpose of IoC container?

Okay, first of all I understand the concept of IoC container! It's used to implement automatic dependency injection so you won't have to manually inject dependencies to class. It can automatically ...
Jhe's user avatar
  • 17
4 votes
4 answers
996 views

How to avoid injecting uninitialized dependencies?

I have some components which require some asynchronous calls to be finished before those components are fully initialized and ready for work. I do not want dependant objects to know about these ...
Anton Petrov's user avatar
-1 votes
1 answer
163 views

Containers Across Operating systems

Curious how containers are portable across development/testing/cloud environments with no worry needed about the underlying infrastructure. Does the Docker Engine essentially standardize operating ...
CloudQuestions's user avatar
2 votes
2 answers
1k views

Does SOLID Require an IoC Container (Automatic Factory)?

The fifth concept in the SOLID principle is the dependency inversion principle. It is heavily related to dependency injection, and Inversion of control, and when any of these concepts are mentioned, ...
Christian Findlay's user avatar
0 votes
2 answers
2k views

Passing runtime-read configuration when working with an IoC container

I've recently "discovered" the IoC realm, and decided to refactor a project I'm working on to use such a container. To be specific - I'm using autofac in C#, in a .NET Core console application. The ...
Timor Gruber's user avatar
122 votes
5 answers
15k views

What's the difference between using dependency injection with a container and using a service locator?

I understand that directly instantiating dependencies inside a class is considered bad practise. This makes sense as doing so tightly couples everything which in turn makes testing very hard. Almost ...
tom6025222's user avatar
  • 1,004
1 vote
3 answers
631 views

How to reduce dependency on IOC Framework (Frameworks in general)

I was watching a presentation by Uncle Bob. In the end of that presentation (last 10 min), He argued that we should abstract everything (Even frameworks) from our business logic. JAVA EE does a great ...
Mr.Q's user avatar
  • 121
9 votes
1 answer
6k views

Should .NET Core class libraries register their own implementations?

Our team had recently a big struggle of deciding whether it is a good practice or not for the .NET Core class libraries to register their own implementations by the fact of providing a ...
Radek Strugalski's user avatar
1 vote
2 answers
268 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 ...
user avatar
0 votes
1 answer
483 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 --> ...
dartNNN's user avatar
3 votes
4 answers
3k 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 ...
Ash's user avatar
  • 219
18 votes
2 answers
2k 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 ...
NMrt's user avatar
  • 487
1 vote
2 answers
157 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....
xeraphim's user avatar
  • 339
6 votes
4 answers
3k 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 ...
Jacob Brown's user avatar
-1 votes
1 answer
796 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 ...
user1787812's user avatar
1 vote
4 answers
1k 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 { ...
overexchange's user avatar
  • 2,305
2 votes
2 answers
921 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 ...
Dennis's user avatar
  • 8,257
0 votes
2 answers
696 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) ...
w0051977's user avatar
  • 7,129
4 votes
3 answers
2k 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 ...
Bartosz's user avatar
  • 597
6 votes
3 answers
3k 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 all ...
John Wu's user avatar
  • 26.9k
2 votes
2 answers
2k 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 ...
grokky's user avatar
  • 177
4 votes
1 answer
253 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 ...
johnny's user avatar
  • 3,679
9 votes
3 answers
966 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 ...
packoman's user avatar
  • 291
2 votes
2 answers
640 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) ...
bloxx's user avatar
  • 23
5 votes
4 answers
2k 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 ...
Robert Harvey's user avatar
4 votes
2 answers
2k 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 ...
Jacob van Eijk's user avatar
0 votes
2 answers
456 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 {} [...
shda's user avatar
  • 121
0 votes
3 answers
565 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 ...
user2871239's user avatar
2 votes
1 answer
541 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 ...
Anders's user avatar
  • 671
4 votes
3 answers
390 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 ...
James's user avatar
  • 141
15 votes
3 answers
3k 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 ...
Sinaesthetic's user avatar
1 vote
2 answers
607 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 ...
Den's user avatar
  • 4,867
13 votes
6 answers
3k views

Questioning one of the arguments for dependency injection frameworks: 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, you ...
oberlies's user avatar
  • 466
0 votes
1 answer
714 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 ...
Ron's user avatar
  • 183
5 votes
3 answers
2k 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 ...
Yorro's user avatar
  • 159
1 vote
1 answer
592 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), ...
luis_laurent's user avatar
-2 votes
2 answers
2k 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&...
EngineerSpock's user avatar
120 votes
7 answers
56k 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, ...
Korey Hinton's user avatar
  • 2,686
3 votes
1 answer
636 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 ...
Jeff's user avatar
  • 215
8 votes
4 answers
3k 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 ...
Jeff's user avatar
  • 215
8 votes
3 answers
705 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 ...
pdr's user avatar
  • 53.7k
18 votes
1 answer
8k 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 ...
Dave Hillier's user avatar
  • 3,938
1 vote
2 answers
408 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 ...
punkouter's user avatar
  • 1,123
6 votes
3 answers
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. ...
Steve3p0's user avatar
  • 181
26 votes
6 answers
4k 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 ...
CraigTP's user avatar
  • 1,564
-1 votes
1 answer
324 views

PocoCapsule project status

Does anybody know the status of this C++ Inversion of Control Container? Any alternative?
Andrea Zilio's user avatar
3 votes
1 answer
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 ...
Andrew's user avatar
  • 133
10 votes
4 answers
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 ...
Homde's user avatar
  • 11.1k
5 votes
1 answer
861 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 ...
Erin's user avatar
  • 2,368