Questions tagged [ioc-container]

In object oriented languages, an inversion of control container (ioc-container) can be used for configuring and managing objects in an application.

In object oriented languages, an inversion of control container (ioc-container) can be used for configuring and managing objects in an application. The container is responsible for managing object lifecycles (creation, initialization, destruction) and configures objects by wiring them together.

Objects managed by the container obtain references to other objects (their dependencies):

  • by explicitly asking the container, using dependency lookup methods on the container
  • automatically, because the container injects the dependencies using one or more dependency injection techniques

Frameworks that provide an ioc-container support one of these methods and often both.

The following frameworks are discussed here at Stackoverflow

For .NET:

For Java:

2163 questions
1
vote
1 answer

Register multiple interfaces that has explicit implementation on a single instance

I am using Autofac and I am not a IoC master. Consider this scenario: public interface IBeforeRequestTask { void Execute(); } public interface IAfterRequestTask { void Execute(); } public class TaskExecutor : IBeforeRequestTask,…
Lincoln Pires
  • 338
  • 4
  • 15
1
vote
0 answers

Ninject MVC: Multiple calls resulting in failure

I always use Ninject MVC to bind my actual Db to the DbContext on run time for some reasons. One problem I have faced when using Ninject is that, when I need to access the bind object in an attribute such as the AuthorizeAttribute, Ninject causes…
1
vote
1 answer

IoC Container - Registering Instance Components

My question is with regards to instance registration in an Autofac IOC container. In some cases, you may want to pre-generate an instance of an object and add it to the container for use by registered components. You can do this using the…
Maz H
  • 151
  • 8
1
vote
1 answer

Session scoped instances in TinyIoC

I need an instance of a class to be created only once per user session. How do I register such a class with TinyIoC? I'm using NancyFx.
ulu
  • 5,872
  • 4
  • 42
  • 51
1
vote
1 answer

DI - Assembly wide install based on generic interface does not register its implementations

I am trying to register Interfaces and their implementations using Castle Windsor. I have a Class called ProductRiskStatusChecks which implements IChecks where IProductRisk implements IValidateDomainObject I tried to install these as…
1
vote
2 answers

Simple Injector Property Injection

How do you perform property injection with Simple Injector. The with Ninject you do is as per bellow: [Inject] public IUnitOfWork UnitOfWork { get; set; } How can I do the equivalent to this with Simple Injector. I tried finding a solution online…
1
vote
2 answers

Unity with the same interface, multiple factories

So the issue, is when I declare: [Dependency] public AuthenticationService _authenticationServices { get; set; } The _authenticationServices will constantly remain null. It isn't referenced, which will throw a Null Reference Exception. I'm…
Greg
  • 11,302
  • 2
  • 48
  • 79
1
vote
2 answers

Why doesn't the following mocking with Ninject.Moq work?

I'm trying to run the following code with Ninject.Moq: [TestMethod] public void TestMethod1() { var kernel = new MockingKernel(); var engine = kernel.Get(); //as I don't need to actually use the interfaces, I don't want //to even…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
1
vote
3 answers

Autofac. Retrieve all services registered as named

I am trying to use named registration in the program. But example from documentation does not work. http://autofac.readthedocs.org/en/latest/advanced/keyed-services.html#named-services public class DbLoggerModule : Autofac.Module { protected…
SoaperPlus
  • 159
  • 2
  • 11
1
vote
1 answer

Tracking instances created by a MEF container

I'm using MEF to create several instances of the same export. I'd like to keep track of the instances I have created, and am either querying the container or using a recomposited collection, but I never get my instances... Here's the code: interface…
Florian Doyon
  • 4,146
  • 1
  • 27
  • 37
1
vote
2 answers

How to construct objects with an IOC container

I believe I understand enough about dependency injection to get started with it, but I'm having trouble understanding IOC containers vs service location, and how to construct my objects utilizing the container. Given: public interface IFooService { …
1
vote
1 answer

Hot-swapping dependencies in Unity

I'm just starting with Unity IOC, hoping someone will help. I need to be able to switch the dependencies in Unity at run time. I have two containers each for production and dev/test environments, "prodRepository" and "testRepository" defined in the…
1
vote
1 answer

Passing dependency injected classes vs a container into an application startup WinForm

I am working on a WinForms application which has been configured into the typical 3 layers of UI, BLL, and DAL. I created a separate project to act as the startup project. Another project was also created to act as a home made dependency injection…
1
vote
1 answer

IoC container resolved DbContext(EF) causing eager loadng of child object in entity

Below is the stripped down version of my original webproject. I have following classes for the Data access project public class DbContextFactory : IDbContextFactory { private readonly DbContext dbContext; public DbContextFactory() { …
RenjithR
  • 13
  • 4
1
vote
1 answer

Castle Windsor (or any IoC framework) and internal dependencies

I'm having some trouble getting my head around using dependency injection with internal types. Although I've been using Castle Windsor for a few years, I've never really had to think about visibility too much, so everything typically ended up being…
Andrew Stephens
  • 9,413
  • 6
  • 76
  • 152