dependency-injection

Dependency injection OR configuration object?

I have the following constructor for my Class public MyClass(File f1, File f2, File f3, Class1 c1, Class2 c2, Class3 c3) { .......... } As can be seen, it has 6 parameters. On seeing this code, one of my seniors said that instead of passing 6 parameters I should rather pass a configuration object. I wrote the code this way because ...

How to do Spring Lookup Method Injection with Annotations?

Is there any way to use Lookup Method Injection using annotations? Given the following class: @Service public abstract class A { protected abstract createB(); } In order to get it to work I have to declare in spring applicationContext.xml the following: <bean id="b" class="com.xyz.B"> </bean> <bean id="a" class="com.xyz.A"> ...

ASP.NET MVC inject per request

I need to inject EF context per request. Is there any way to implement it? ...

Resolving a type without registering first - prism 4 and Untiy

First of all I would like to remark I am new with the concept of prism, DI and containers. I am looking on one of the code samples provided with the Prism Library: The code simply injects a view with the "Hello World" string (in a TextBlock element) to a region in the shell. When the application starts-up, it creates a new BootStrapper ...

Spring injection question

Hello: I have a static class ResourceFetcher with a static method fetchResource(String reference). I want to inject the resource returned by it into another class JobRunner. Can anyone specify the cleanest way of doing this? I do not want to pass ResourceFetcher into JobRunner. In fact, I have an enum with set of keys, and I need to ...

Difference between "Inversion of Control", "Dependency inversion" and "Decoupling"

I'm reading theory about dependency inversion and decoupling and I can't see the difference between the two. Dependency inversion talks about decoupling functional components so that higher level components don't depend on lower level components. Decoupling talks about the same thing and how to achieve it. But then we have IoC Containe...

WCF Dependency Injection using Castle Windsor - Please help ??

I have a WCF service which calls the business component which calls the repository and I have got it end to end working using Castle Windsor using it's WCF Facility. The WCF Facility registration and rest of the component registration happens in the Global.asax file like this. public class Global : System.Web.HttpApplication ...

How to specify exceptions to be thrown by an implementor of an interface

I'm currently developing a solution and have designed it in a way such that it strongly implements the strategy/provider pattern. As such the solution exposes a number of interfaces and contains default implementations of these interfaces which can be replaced via a DI type methodology. Where the host application uses a number of these...

ObservableCollection via Constructor Injection - Notification of Changes To Collection?

I have the following two classes: (1) IViewModelManager (2) WorkspaceViewModel IViewModelManager has an ObservableCollection. IViewModelManager is injected into WorkspaceViewModel's constructor. I have a View that binds to WorkspaceViewModel - and in the view is a ListBox that needs to bind to a collection in WorkspaceViewModel. If ...

Ninject.Web.Mvc add-on not working with ASP.NET MVC 2

I'm using the Ninject.Web.Mvc (the MVC 2 version) add-on with ASP.NET MVC 2. This is an excerpt of my Global.asax.cs: protected override void OnApplicationStarted() { AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes; // RegisterAllControllersIn() is not available in the MVC 2 version of Ninject } protec...

Looking for books on IoC

Hi, I'm having a hard time finding books (eBook or hard copy) on any dependency injection frameworks. I'd really love one on Ninject but I can't seem to find any, not even for the popular Windsor Castle. ...

Is replacing strategies injected via a DI container a valid deployment mechanism?

I'm creating an application which uses a DI Container for injecting strategies into it. When deployed, if I require those strategies to change, is it a valid deployment strategy to deploy a new assembly with the new strategies and ammend the configuration file for instructing the DI container of which strategy to use? My concern is that...

NUnit integration tests and dependency injection

I'm currently making use of Castle Windsor version 2.1 as my container and would like to perform integration tests using the services registered with it. Currently, I do this my using the Common Service Locator to retrieve my service instance and perform my integration tests against it as such: var myService = ServiceLocator.Current.Ge...

Can anyone recommend an IoC container for ASP.NET 2.0 Webforms?

As the title says, I'm looking for recommendations for an IoC container to use with an ASP.NET 2.0 Webforms app. I believe that some containers are .NET3.5 or newer only. ...

StructureMap strongly-typed constructor arguments

I have a bit of StructureMap config like so: x.ForConcreteType<OrderProcessor>().Configure .Ctor<string>("param1").EqualToAppSetting("setting1") .Ctor<string>("param2").EqualToAppSetting("setting2") .Ctor<string>("param3").EqualToAppSetting("setting3"); This works, but it is a bit of a magic-string approach. If I add or re...

DI (Autofac) in a plugin architecture: Is one separate DI container per plug-in OK?

I am trying to introduce DI (with Autofac) into an existing Windows Forms application. This application has a basic plug-in architecture where each plugin displays its own form. On startup, the application scans registered assemblies for types that implement IPlugin, and then activates these using Activator.CreateInstance: public inter...

Mockito: Injecting Mocks Throughout Control Flow

I'm still learning mockito and right now I'm learning how to inject mocks. I have an object under test with a particular method that depends on other objects. Those objects, in turn, depend on other objects. I want to mock certain things and have those mocks be used everywhere during execution--throughout the control flow of the metho...

How to use an IoC Container?? I don't get it

Here's what I know so far: DI lets me build reusable, unit-testable components DI is verbose because it requires that I explicitly set the dependencies (via constructor or method. I still don't understand the interface injection though). This is why a container or a service locator is needed. Container is better than service locator be...

How many dependencies should be passed using a ctor?

If I have class A which has a dependency on class B, then class B could be passed in to the ctor of class A. What about if class B has a dependency on class C, does that mean class A should receive all required dependencies upon construction ? ...

Dependency injection in (python) google-app-engine

I want to achieve maximum testability in my google-app-engine app which I'm writing in python. Basically what I'm doing is creating an all-purpose base handler which inherits the google.appengine.ext.webapp.RequestHandler. My base handler will expose common functionality in my app such as repository functions, a session object and the l...