dependency-injection

What other IoC containers have an IInitializable like feature?

I've been using Castle Windsor in my previous project and I liked it a lot. For my current project I'm looking to use a different IoC container. Castle Windsor hasn't had any new releases since 2007 and is still not at version 1.0 so it is hard to justify using it in a commercial environment. One of the things I like about Castle Windso...

Using DI to add new equations for calculating using 2 numbers

I am working on a program where I want to be able to add functionality using DI, C#, so I will create an example to see if this is possible. I have a program that a user enters any two numbers. The program then looks at all the plugins in an xml file and uses those classes that are injected to calculate with these two numbers. So, I cr...

Dependency Injection and ModelStateWrapper

Hi, in tutorial Validating with a service layer constructor for Product Service looks like this: ProductService(IValidationDictionary validationDictionary, IProductRepository repository) and its instance in default controller constructor is created like this: public ProductController() { _service = new ProductService(new Mode...

What is the problem with not using Spring

I am trying to understand Spring. I have read about it and done some tutorials. I kind of get the IoC paradigm and the fact that DI is its implementation in Spring. My question is this: What do you lose by not using Spring? I understand this is a big question and somewhat subjective. But if you could write a few dot points or give an ex...

MVVM - Does the View really need have to have a default constructor?

I'm just getting started with the MVVM pattern in WPF and I decided that the most elegant way to structure my code was injecting the view-model in to the view's constructor. This is all well and good, but ReSharper gives a warning in the XAML that my view doesn't have a default constructor. I'm assuming that this is so that I can constr...

Castle Windsor passing constructor parameters

I have an IAddress class with a few properties. I then have a concrete type that implements this interface. This concrete type has a couple of different constructors I could use. How can I pass parameter values to one of these constructors at run-time? I cannot use the config file as I will be reusing this concrete type multiple time...

Contextual Binding with Spring.net

In other IoC containers like ninject you can setup contextual binding pretty easily. I was wondering if contextual binding was supported by the Spring.net IoC container? ...

Unit testing data access layer using Unity Framework

I am getting close to finish my database, so far, 16 tables so far, and I need to unit test my DAO layer for this ASP.NET project. I am using the Unity Framework to decouple the layers, so I expect that I should be able to assign the DAO layer to my unit tests, which will be testing against the interfaces since the concrete classes are ...

Can I pass constructor parameters to Unity's Resolve() method?

I am using Microsoft's Unity for dependency injection and I want to do something like this: IDataContext context = _unityContainer.Resolve<IDataContext>(); var repositoryA = _unityContainer.Resolve<IRepositoryA>(context); //Same instance of context var repositoryB = _unityContainer.Resolve<IRepositoryB>(context); //Same instance...

Law Of Demeter on Factory Pattern and Dependency Injection

hello all I have a question regarding dependency injection. say i want to create a class call it, WebGetTask WebGetTask would need a dependency to HttpService bad code 1 Code: private HttpService httpService; ... List<WebGetTask> list = new ArrayList<WebGetTask>(); for(...) { list.add(new WebGetTask(httpService)); } ...

Dependency Injection: Separating the Call Graph from the Construction Graph

I'm trying to exercise the principles of Dependency Injection, and I'm having some difficulty doing so. I have a function that periodically goes off to my database, retrieves a list of products, and then runs a battery of tests against those products in order to determine their safety. If one or more of the products is found to be unsa...

IoC and dynamic objects

Hi I'm having trouble figuring out how to resolve objects that depend on objects that are non deterministically created at runtime. What is the best approach? Imagine something like a word processor. For each document you open, you probably want to create a large number of objects that depend on the document object. As an example, yo...

Is there a Dependency Injection Framework for Delphi or Free Pascal?

For some of my Delphi / Free Pascal projects I consider using Dependency Injection. Are there already implementations available (or in development) which provide some basic DI (IoC) functionality? Edit: I am not looking for a .NET based solution for Delphi.Net or Prism - in this case, the question would have been: which one should I pic...

Structuremap Stackoverflow Exception

I keep getting a stackoverflow exception when I call "GetInstance" (the last line). All, yes ALL of my types implement ITracker. MultiTracker has a constructor with a single parameter, which is an array of ITracker's. It seems like StructureMap is ignoring the fact that I told it that MultiTracker is the default class I want when reques...

Dependency Injection resolve and unit testing

Hi I'm trying to learn dependency injection and have come across a problem, when unit testing the application. I'm writing a console application and the container is created and initialized in Main(), it's available as a get-property in Program.Container, so anywhere in my application I can call Program.Container.Resolve<..>(). I have...

Is dependency injection just another name for the strategy pattern?

Are these terms equal or are there any important differences between dependency injection and the strategy pattern? Too me it seems like Martin Fowler just renamed the strategy pattern with a catchier name, am I missing something? ...

Why does Spring's @Configurable sometimes work and sometimes not?

I'm trying to use automatic dependency injection via Spring's @Configurable annotation w/ @Resource on the fields needing injection. This involved some setup, like passing spring-agent.jar to my JVM. For the full details see here. It works... mostly. When my Tomcat is booting up, I see the AspectJ init messages, my User objects automati...

What's the best way to handle circular dependencies amongst objects?

In my code, I have the the following objects: ErrorManager - controls how errors are logged in the application ConfigManager - controls how the configuration information is obtained On the project I'm working on, the ErrorManager needs to pull configuration information using the ConfigManager instance while the ConfigManager uses the...

Ordered resolution of types from Castle Windsor AllTypes

I have a group of classes that implement an interface for my application start-up activities. Here is the registration code: private static void ConfigureContainer() { var container = new WindsorContainer(); container.Register(AllTypes.Of<IStartupTask>() .FromAssembly(Assembly.GetExecutingAssembly())) ... ...

Can someone describe some DI terms to me?

I'm in the process of writing a DI framework for PHP 5, and I've been trying to find the 'official' definitions of some words in relation to dependency injection. Some of these words are 'context' and 'lifecycle'. And also, what would I call the object that gets created/injected? Finally, what is the difference between components and ser...