Inversion of Control

learn more… | top users | synonyms

13
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, ...
2
votes
4answers
220 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 ...
0
votes
1answer
65 views

IoC, Unity: Creating a component with additional concrete parameters

I am struggling with the following issue. Let's say I have a component that performs operations on guests and rooms, and uses a number of abstract interfaces, along the lines of: class HotelManager { ...
3
votes
3answers
76 views

Missing dependencies at compile-time with IOC

Thanks to my new job, I recently discovered the inversion of control design principle (with windsor castle in C#). I really enjoy using it but something's bothering me. For me the good part about ...
8
votes
1answer
287 views

How is Inversion of Control related to Dependency Inversion

In many articles all over the web the terms Inversion of Control and Dependency Inversion Principle seem to be mixed up and used as synonyms (further confusion is enforced by the tools that are called ...
1
vote
1answer
120 views

How far do I separate Model code from Controller code when writing MVC?

I have some code where Controller depends on the Model, and in my case Model acts like a Database Access Object. use FQDN\Model; class Controller { /** @var FQDN\Model */ private $model; ...
0
votes
2answers
83 views

What is the name for user-defined methods / functions that get called implicitly? [closed]

I want to mark such methods in my application code with a comment that highlights that these methods are expected to get called by the framework / compiler the application is written for, even if the ...
3
votes
2answers
109 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
127 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 {} [...
6
votes
1answer
455 views

IoC/DI design for class library

I am refactoring and introducing unit tests in a large application. It's currently a collection of static classes with static methods that return data, like such: // in data access project public ...
2
votes
1answer
193 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 ...
1
vote
1answer
219 views

Does merely parameterizing a dependency meet the requirements for Inversion of Control?

When I find a concrete dependency inside an extension method, I have been attempting to remove the (concrete) dependency by parameterising it like so // original implementation public static List<...
4
votes
3answers
361 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 ...
2
votes
1answer
386 views

Applying initialization-on-demand holder idiom at variable level rather than class

I was looking for the idiomatic way to implement thread-safe lazy initialization for a configuration collection retrieved from the DB inside a Spring bean. I decided to adapt the initialisation-on-...
2
votes
1answer
642 views

IoC, Unity and passing parameters (or a way to avoid doing so)

While the concept of IoC isn't foreign to me, I'm new to Unity and I'm having trouble connecting the metaphorical dots, so to speak. In our project we have a class library for logic, then several ...
14
votes
3answers
1k 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 ...
45
votes
5answers
9k views

IOC Containers break OOP Principles

What is the purpose of IOC Containers? The combined reasons for it can be simplified to the following: When using OOP/SOLID Development principles, Dependency Injection gets messy. Either you have ...
1
vote
2answers
348 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 ...
1
vote
1answer
113 views

Creating an object that is ready to be used & unset properties - with IoC

I have a question regarding the specifics of object creation and the usage of properties. A best practice is to put all the properties into a state such that the object is useful when its created. ...
2
votes
1answer
425 views

How can I identify a namespace without using a string literal?

My team has a lot of IOC conventions that look something like... if (type.Namespace == "My.Fun.Namespace") { // do stuff } Of course, maintaining this kind of thing becomes brutal after awhile, ...
9
votes
2answers
579 views

Compile-time IOC

Has anyone started a project to do IOC at compile time (possibly using Roslyn or Linq MethodInfo emit)? My experience with IOC containers has thus far been great, baring a few small issues Many IOC ...
0
votes
1answer
112 views

How to apply IoC (or something similar) to a constant?

I have the following class with the following members: public class RegistrationPresenter : EPiPresenter<IRegistrationView, LoginPage>, IDisposable { private readonly static string[] ...
12
votes
2answers
1k views

How do you manage config with dependency injection?

I am a big fan of DI/IOC. It is great for handling/abstracting away hard dependencies, and makes life a little easier. However I have a small gripe with it, which I am not sure how to solve. The ...
3
votes
3answers
2k views

Should IoC container be part of portable library?

I am seeing the benefits of Portable Class Libraries for centralizing Models and ViewModels to a single code-base. Where should dependency injection management (IoC container) take place, though? My ...
4
votes
3answers
438 views

Is Convention Over Configuration “Knowledge in the World” or “Knowledge In Your Head”?

In Don Norman's seminal work "The Design of Everyday Things", the author coined the phrases and explains the difference between "Knowledge in the World" and "Knowledge In Your Head"; an example of ...
1
vote
1answer
297 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), ...
67
votes
6answers
15k 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, ...
6
votes
5answers
12k views

Dependency Injection Confusion

I think I have a decent grasp of what Dependency Inversion principle (DIP) is, my confusion is more around dependency injection. My understanding is the whole point of DI is to decouple parts of an ...
1
vote
3answers
276 views

Shall we always use IoC in our designs?

I was studying Mediator Pattern and I noticed that to use this pattern you should register the Colleagues into Mediator from the Colleague concrete classes. for that we have to make an instance of ...
2
votes
1answer
344 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 ...
16
votes
1answer
5k 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 ...
13
votes
5answers
2k views

Does following TDD inevitably lead to DI?

I learned to do Test Driven Development (TDD), Dependency Injection (DI) and Inversion of Control (IoC) all at the same time. When I write code using TDD I always end up using DI in my class's ...
2
votes
2answers
655 views

DI/IoC in Java for a .NET'er used to Castle.Windsor

Is there a Java DI container that works in a similar way to the most excellent Castle.Windsor container on the .NET side? The Java containers I've had a look at all seem to rely on annotations (...
6
votes
1answer
4k views

Is IoC feasible in winforms?

I'm coming back into the winform world after being in the web world for a while. Is it common or otherwise feasible for developers to use IoC in winform? My concern is mainly with performance. I ...