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

Autofac Registering Multiple Containers

I have a MVC application, and i am using Autofac to resolve dependencies. I have a situation where i have to create 2 containers and runtime should decide which container to use based on a condition. The condition is if the controller Home is…
user2388339
  • 27
  • 1
  • 4
1
vote
2 answers

Resolution Problem with HttpRequestScoped in Autofac

I'm trying to resolve the AccountController in my application, but it seems that I have a lifetime scoping issue. builder.Register(c => new MyDataContext(connectionString)).As().HttpRequestScoped(); builder.Register(c => new…
Page
  • 9,945
  • 5
  • 37
  • 45
1
vote
1 answer

AnnotationConfigApplicationContext.getBean returns a different bean, Spring

I have a problem that I have a ClassA needs RoomService to be injected, and it works fine that I find in ClassA, the roomService's id is the same. While for some reason, I need roomservice to create room instance based on some input param for me, so…
JaskeyLam
  • 15,405
  • 21
  • 114
  • 149
1
vote
1 answer

WindsorCastle child container resolving parent dependency

My task is to inject specific non-direct child dependency if a top level dependency is of some type. I've tried achieving this with subcontainers, but it does not work as I expected. I have a next class hierarchy: PRMController: ApiController ->…
Alex M
  • 2,410
  • 1
  • 24
  • 37
1
vote
0 answers

How can I resolve a dependency on something on the current request?

I'm setting up dependency injection in my ASP.NET Web API application. I have a scenario where a dependency has a dependency on something on the current request (the hostname, for example). So how can I use the current request as a…
John Rutherford
  • 10,704
  • 7
  • 30
  • 32
1
vote
1 answer

How to conventionally set the LifeTimeManagement in a UnityContainer?

In my app, I use a messenger interface IMessagePublisher in a generic realization class SimpleMessenger. For a same type T, there must be one and only one SimpleMessenger instance wich has to be ContainerControlledLifetimeManaged without…
IronSlug
  • 492
  • 3
  • 15
1
vote
1 answer

WCF with StructureMap: Operation could destabilize the runtime

I encountered this weird error when I used WCF with StructureMap. I also tried to search the stack and there are some answers that recommend to install a hotfix: Operation could destabilize the runtime in StructureMap But I cannot install the hotfix…
Vu Nguyen
  • 3,605
  • 3
  • 22
  • 34
1
vote
2 answers

Microsoft.Practices.ServiceLocation and TryGetInstance

Why Microsoft.Practices.ServiceLocation.IServiceLocator does not offer TryGetInstance()? I need to get generic validator instance ServiceLocator.Current.GetInstance>() but not all Entities has registered validator. The…
Feryt
  • 2,262
  • 2
  • 22
  • 32
1
vote
2 answers

Specifying type when resolving objects through Ninject

Given the class Ninja, with a specified binding in the Ninject kernel I can resolve an object doing this: var ninja = ninject.Get(); But why can't I do this: Type ninjaType = typeof(Ninja); var ninja = ninject.Get(); What's…
stiank81
  • 25,418
  • 43
  • 131
  • 202
1
vote
1 answer

ServiceStack self-hosted application with per-request lifetime scope

Working with ServiceStack I've stuck with the problem of objects lifetime management in self-hosted web application. My requirements: Need of per-request objects lifetime scope. I'm using Castle Windsor IoC with implemented ServiceStack IoC…
1
vote
1 answer

Autofac. Register HttpContext.Session per tenant

I'm developing a multi tenant application. For now what I want to achieve is obtaining a unique instance of HttpContext per tenant. Each tenant has its own database. All tenants share same functionality (There aren't any tenant X specific…
1
vote
1 answer

MDB with spring beans doesn't autowire beans from another package

I am using following MDB to connect to WMQ: @MessageDriven(name = "EventListener", activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName =…
1
vote
1 answer

How to mock dependencies for a WebApi 2 controller when using MEF 2 (System.Composition)?

With MEF (System.ComponentModel.Composition) it's possible to add mock objects to the container. container.ComposeExportedValue(mock.Object); ref: How to use Moq to satisfy a MEF import dependency for unit testing? How is this possible with the…
Boggin
  • 3,251
  • 3
  • 33
  • 48
1
vote
1 answer

Implementing auditing using Autofac if it support method interception?

I'm planning to use Autofac IoC for my project where I must implement auditing (Who, What is doing in application). I was already read a lot of articles on this subject (auditing). My intention was to use method interception to implement this…
ITGoran
  • 442
  • 1
  • 7
  • 18
1
vote
1 answer

Simple Injector Scope for specific LifeStyle

Is there a way to define a scope for a specific lifestyle? I am attempting to implement my own scope that I want to persist across an application, but internally I also create another scope, and then a request to GetInstance returns the inner…
tris
  • 1,780
  • 3
  • 18
  • 28