dependency-injection

Global State and Singletons Dependency injection

this is a problem i face lot of times when i am designing a new app i'll use a sample problem to explain this think i am writing simple game.so i want to hold a list of players. i have few options.. 1.use a static field in some class private static ArrayList<Player> players = new ArrayList<Integer>(); public Player getPlayer(int...

Unity - InjectionProperty results in null properties?

When I container.RegisterType<IInterface, MyClass>(); everything works, and all dependent properties annotated with: [Dependency] are resolved through the container. But, I now have an int property that I'd like also to resolve through the container. It's not passed in the constructor, but just as a public property. So I tried ...

Example of Dependency Injection with only base class

Is it possible to do DI without any third party tools? I've read about people doing it with an abstract class and interface before they discovered some DI framework. How is ID done in that very basic form? ...

Autofac, ASP.NET and Microsoft.Practices.ServiceLocation

I've been working thru the details of implementing IoC in my web apps but in a way that leverages Microsoft.Practices.ServiceLocation. I am specifically using Autofac and the asp.net integration, but I wanted to leave myself open to other containers. Along the lines of this question, i was concerned about how to access the container in m...

If I store a member as an object, will I incur an object copy during constuction?

If the constructor for Door looks like this: Door::Door(Doorknob doorknob) : m_doorknob(doorknob) { } Then you would instantiate a Door like this: Doorknob doorknob; Door door(doorknob); // Does an object copy of doorknob occur here? It seems like if you store Doorknob as a pointer, you can explicitly avoid the copy: Door::Door(D...

Castle Windsor: Constructor resolution order

Hi guys Just wondering how Castle Windsor determines which constructor to resolve when there are multiple constructors present. Cheers Anthony ...

IAuthorizationFilter + Ninject2

I'm currently using Ninject2 to bind the various services and repositories in my MVC app. That part seems to be working just fine. Now I'd like to also bind my own class to IAuthorizationFilter and all actions that have the attribute set. I've created a class that inherits from AuthorizationFilter and Implements IAuthorizationFilter. ...

Unity Container: use ContainerControlledLifetimeManager by default for "Resolve" method group

Hi! How to fill TODO to make this test pass? class MyClass { } [Test] public void Singleton_by_default_test() { var parentContainer = GetUnityContainer(); var container = parentContainer.GetChildContainer(); // TODO: Add magic here (but do NOT explicitly register MyClass in container!) Assert.AreSame(containe...

What is the reasoning behind this ioc behavior (Resolve with multiple registered components)

Seems like a standard approach for an ioc when given a scenario like (C# windsor): container.AddComponent<ILogger, HttpLogger>(); container.AddComponent<ILogger, SmtpLogger>(); var logger = container.Resolve<ILogger>(); Would be that when resolving the component, the first registered ILogger (HttpLogger in this case) is the only cand...

DI Container: inject the right components from a collection of same types?

I'm trying to hack my own dependency injection container in PHP, based on constructor injection. The container instantiates complex objects and inject them with the required objects based on the type hints in the constructor using reflection. One thing I obviously stumbled upon is the fact that I can register multiple components that ca...

What is the equivalent of Container.GetAllInstances<T> in NInject?

I'm building a message broker with NInject, and I need to find all instances in the container that implement Consumes, an interface that marks the class as being able to consume a particular message type. Is this scenario supported? ...

What are the shortcomings and annoyances in Ninject and/or StructureMap DI/IoC implementations

I'm looking to replace a home-grown IoC implementation with a standard one. My needs are very simple, translating an interface type into a newly created concrete class. I think you'll agree basically any framework will handle this. Currently I'm narrowing the field down to the following: Ninject StructureMap So again, the question...

Handling Runtime dependencies

Dependency injection is a useful technique but what approach is recommended when faced with runtime dependencies? e.g. Say you want to glue an event to an event processor depending on the type of the event and the user who initiated the request. public interface Event {} public interface EventProcessor { public void handleEvent(Ev...

Help getting DI/IoC in house

Hi all, I am trying to introduce DI/IoC programming methodology into our development group, but one of the developer asked the following question: Why do we need it? Is there any concrete example that can show me the benefit of using DI/IoC framework like windsor castle? Therefore, I am asking if there are any case study or article o...

Injecting an object into a HttpSessionAttributeListener via Guice ?

Configuration: Guice 1.0, Apache Tomcat 6.0 I am currently manually injecting objects configured in a Guice Module, into my servlet, using this method: public void init( ServletConfig config ) throws ServletException { super.init( config ); ServletContext sc = config.getServletContext(); Injector injector = (Injector) sc ...

How should I handle my Entity/Domain Objects using IoC/Dependency Injection?

I'm currently using PLINQO to generate all my Entities from the database. Recently, I've started to use dependency injection using StructureMap, and as part of the learning process of "separating my concerns". I've noticed that all the generated Entity classes contain highly-coupled properties using EntitySet, part of LINQ, which make m...

Inject log object in Grails class outside of grails-app

I have a class in src/groovy in my grails project. How do i make a log field that gets injected with the correct logger for that class ? Is there a commons logging or just log4j in grails ? ...

Lazy resolution of dependency injection

I have .net classes I am using unity as IOC for resolving our dependencies. It tries to load all the dependencies at the beginning. Is there a way (setting) in Unity which allows to load a dependency at runtime? ...

Is ninject considered a container?

Hi, I was talking with someone and mentioned I was learning IOC and was using ninject to get the feel for things. He asked me what container I was using? I told him ninject. Having no idea what he was referring to, I know there is castle windsor products that are more popular. Can someone clear this up for me? What am I missing here...

Dependency Injection/IOC when extending the Eclipse IDE

Suppose I am building a very simple eclipse plugin for creating new java projects. I obviously will create a new Wizard for the extension point org.eclipse.ui.newWizards. However, what I really want is to allow other plugins to implement a service that drives this new wizard. So in theory we have three plugins: My "Primary Plugin" (w...