Questions tagged [inversion-of-control]

Inversion of control (IoC) is an abstract principle describing an aspect of some software architecture designs in which the flow of control of a system is inverted in comparison to procedural programming.

In traditional programming the flow of the business logic is controlled by a central piece of code, which calls reusable subroutines that perform specific functions. Using Inversion of Control this "central control" design principle is abandoned. The caller's code deals with the program's execution order, but the business knowledge is encapsulated by the called subroutines. In practice, Inversion of Control is a style of software construction where reusable generic code controls the execution of problem-specific code. It carries the strong connotation that the reusable code and the problem-specific code are developed independently, which often results in a single integrated application. Inversion of Control as a design guideline serves the following purposes:

  • There is a decoupling of the execution of a certain task from implementation.
  • Every system can focus on what it is designed for.
  • The systems make no assumptions about what other systems do or should do.
  • Replacing systems will have no side effect on other systems.

Dependency injection and Inversion of Control are closely related. The difference between them is discussed in this question.

Wikipedia: Inversion of Control

Related Patterns

4379 questions
2
votes
2 answers

Would a static reference to an IoC Container in an MVCApplication cause memory leaks?

I am experiencing memory leaks in an ASP.Net MVC 3 application and I suspect it may be an issue with the IoC container. The MvcApplication creates a WindsorContainer object, populates it and then stores it in a static field like this: public class…
Richard
  • 1,122
  • 1
  • 7
  • 14
2
votes
2 answers

When and where todo dependency injection.Could you clarify?

Getting more and more familiar with DI but I still have few niggles. Read few articles where it says "Injection must be done at the entry point" Suppose I have a situation where we have wcf Services and these are used both by internal win/web…
user9969
  • 15,632
  • 39
  • 107
  • 175
2
votes
2 answers

Using IoC to resolve model objects in Action Methods

I'm using IoC container for dependency injection in Asp.Net MVC 3 and everything seems perfect until I started to write Action methods in my controller. What is the best way to create entity/model objects within the action methods? Sometimes models…
Mat J
  • 5,422
  • 6
  • 40
  • 56
2
votes
1 answer

Validating commands before execution

In the system I'm currently building, I use the command pattern to carry out all operations possible. I have chosen the CommandMessage and CommandHandler approach, separating logic from data. This works fine for now, but I've run into a problem -…
2
votes
4 answers

Unity Best Practices with .NET Framework Classes

I am just getting started using any DI/IoC toolset and have a very basic question. I am using Unity as we will also be using a number of the Enterprise Library blocks throughout the application. The question that I have is around the dependencies…
2
votes
1 answer

Autowired field gives me null exception

I have a class that uses a method from a bean. I'm trying to inject that method into my class using @Autowired, but it gives me NullPointerException. public class ChangePasswordServiceImpl extends RemoteServiceServlet implements …
João Daniel
  • 8,696
  • 11
  • 41
  • 65
2
votes
2 answers

How do you get the WPF / XAML designer to work with custom classes with dependencies?

I'm using a custom class to perform validation in a WPF app and have defined a class which inherits from ValidationRule. The class has a dependancy which I would like AutoFac to inject at runtime, but the Visual Studio 2010 XAML designer needs a…
2
votes
1 answer

Why does my Ninject DI application fail with an ActivationException?

I'm new to IoC/DI frameworks. The first one I am trying is the Ninject framework. It seems straightforward, but I can't get my console application to run. I keep getting an ActivationException stating: "Error activating MainWindow: the…
willem
  • 25,977
  • 22
  • 75
  • 115
2
votes
1 answer

Resolving MVC Controller with WindsorControllerFactory

I'm new to Windsor, so Here is my installer: public class ControllersInstaller : IWindsorInstaller { public void Install(IWindsorContainer container, IConfigurationStore store) { …
2
votes
1 answer

Should thoses kind of service go injected in a base class ? (versus static classes)

I was wondering.. if i have services such ILoggingService, IMailerService, ICacheService. Those are part of the infrastructure somehow. However, would you make them as a static class or would you inject them in a base class so that all derived…
Rushino
  • 9,415
  • 16
  • 53
  • 93
2
votes
2 answers

Inject two instances of object

introduction The start is easy: let's say I have a basic controller which uses a Data Access object (inside it uses Entity Framework) to get an entity: public class SomeController : Controller { private readonly DataAccess dataAccess; public…
2
votes
0 answers

Why is the _bin_DeployableAssemblies folder specific to web applications?

The _bin_DeployableAssemblies folder was added in VS 2010 SP1 as a common way to pull in assemblies for which no hard dependency exists. I believe it was originally added as a way to allow folks to bin-deploy MVC, but it seems useful in environments…
Emil Lerch
  • 4,416
  • 5
  • 33
  • 43
2
votes
1 answer

Ninject 2.2 can't support WCF with InstanceContextMode.Single

I have a WCF service with InstanceContextMode set to single then Ninject 2.2 can not support it. and Ninject 2.3 is still beta, if I use it, my Ninject 2.2 code in global.asax can't work with Ninject 2.3 library Can anyone/Ninject Author give an…
Li Tian Gong
  • 393
  • 1
  • 6
  • 16
2
votes
1 answer

Injecting a view model dependency with a non-default constructor

In windows phone application I have a custom user control that is databound to an instance of a BookProgressInfo class. Whenever BookProgressInfo changes, a…
Maxim V. Pavlov
  • 10,303
  • 17
  • 74
  • 174
2
votes
2 answers

Injecting dependency into DTO

Introduction I'm using ASP.Net MVC3. My Controllers talk to a service layer, and the service layer talks to a Data Acces layer which uses Entity Framework. I get a specific entity using Entity Framework. This entity is converted into a DTO. Then I…