dependency-injection

Can someone explain Microsoft Unity?

I've been reading the articles on MSDN about Unity (Dependency Injection, Inversion of Control), but I think I need it explained in simple terms (or simple examples). I'm familiar with the MVPC pattern (we use it here), but I just can't really grasp this Unity thing yet, and I think it's the next step in our application design. ...

Making a class follow OCP - Factoring functions into objects

I have a class to which I'm constantly adding to. public class OrderRepository{ public void Add(IEnumerable<Order> orders){} public void Update(IEnumerable<Order> orders){} public void Remove(IEnumerable<Order> orders){} public void Expedite(IEnumerable<Order> orders){} public void GetOrderData(Order order, DateTime...

Dependency Injection and Runtime Object Creation

I've been trying to follow the principles of Dependency Injection, but after reading this article, I know I'm doing something wrong. Here's my situation: My application receives different types of physical mail. All the incoming mail passes through my MailFunnel object. While it's running, MailFunnel receives different types of messag...

Is it OK to pass parameters to a Factory method?

One of the ways to implement Dependency Injection correctly is to separate object creation from business logic. Typically, this involves using a Factory for object creation. Up until this point, I've never seriously considered using a Factory so I apologize if this question seems a little simplistic: In all the examples of the Factory...

Is this an example of Inversion of Control?

I just finished James Kovac's article on Inversion of Control and Dependency Injection and then used what I learned to make my own IoC/DI example below. I'm quite satisified with this example since it: satisfies the testability aspect of IoC in that it instantiates Customers by passing both a Repository and a MockRepository also the ...

Wiring code in JavaScript

I'm currently facing a conundrum: What is the right way to wire together 2 javascript objects? Imagine an application like a text editor with several different files. I have some HTML page that represents the view for the notebook. I have a file notebook.js that contains class definitions for NotebookController and Notebook View. No...

Why is an IoC/DI container called a 'container'?

I'm just trying to understand where the label 'container' came from. Anyone know? Seems like many things could be called 'containers'. ...

Doesn't Spring's dependency injection break information hiding?

Coming from a C++ background I have to master the complexity of the Java world and its frameworks. Looking at the spring framework for DI I am finding it difficult to believe that I have to make each setter function which will be subject for DI public. Doesn't that requirement break the principle of information hiding? Of course I...

In Java, given an object, is it possible to override one of the methods?

I have an object of class A. I want to override one of the methods of that class. Can this be done? More specifically, I have an object that is being injected into a field. I need to override one of the methods, before I can use it. I am trying to see if Reflection could help solve the problem. Note that the method that I am trying o...

IOC dependency injection deployment (bin ? GAC ?)

Are there any deployment requirements for the most popular IOC containers (example: Windsor, Ninject, Unity, StructureMap, Autofac) ? Do they all deploy the same? If you're on a shared host, what challenges will that present (ex. medium trust, etc...) Can they be bin deployed? GAC deployed? Any web-hosters that come "IOC-ready"? ...

Castle Windsor and auto-registration

I'm a Castle n00b, and am using the Fluent API in Castle Windsor to auto-register implementations to services based on a naming convention (ISomething is implemented by Something). One thing I wanted to support is for auto-registration to pick up dependencies that are in separate dlls, and auto-register those, as well. So: IFoo is impl...

Testing Dependency Injection Configuration

I'm using Unity for dependency Injection. This seems to help when I'm testing my objects because I can mock out all dependencies. However, how am I supposed to test that my configuration is valid? For example, I change the Unity configuration in the app.config, and of course, the project will build fine. My tests are currently only test...

Autofac in web applications, where should I store the container for easy access

I'm still pretty new to using Autofac and one thing I miss in the documentation and examples is how to make it easy to get to the configured container from different places in a web application. I know I can use the Autofac controller factory to automatically resolve constructor injected dependencies for controllers, but how about the ...

Strange behaviour with StructureMap / ASP.MVC / Visual Studio / LinqToSql

I have been using the new MVC framework with StructureMap recently and have had good results overall, however, I keep running into a very strange error that I cannot understand or work out how to resolve. This is my architecture: DBContext - linqToSql data context. IRepository - contract defining data methods. IService - contract def...

In WPF, how can a dynamically loaded element access its parent's elements?

In Window1.xaml I have menu and display area: <Menu x:Name="TheMenu" Width="Auto" Height="25" DockPanel.Dock="Top"/> <ItemsControl x:Name="MainContent" DockPanel.Dock="Top"/> In Window1.xaml.cs I dynamically load in a menu item: MenuItem menuItemEmployees = new MenuItemEmployees(this); TheMenu.Items.Add(menuItemEmployees); In MenuI...

Elegantly reducing the number of dependencies in ASP.NET MVC controllers

We are developing what is becoming a sizable ASP.NET MVC project and a code smell is starting to raise its head. Every controller has 5 or more dependencies, some of these dependencies are only used for 1 of the action methods on the controller but obviously are created for every instance of the controller. I'm struggling to think of a...

Controller/Routing Errors with js, img files using a CommonServiceLocator ControllerFactory

I've set up an ASP.NET MVC RC2 application to use a custom controller factory backed by a CommonServiceLocator (using StructureMap). Routing to and instantiating controllers works fine, but for some reason I'm getting exceptions when trying to access .js, .jpg, or any other static file. Here's the ControllerFactory code: public class ...

How to get Unity's automatic injection to work on interface injected constructors?

The Unity documentation states: if a class that developers instantiate using the Resolve method of the Unity container has a constructor that defines one or more dependencies on other classes, the Unity container automatically creates the dependent object instance specified in parameters of the constructor This is gre...

What does a Dependency Injection framework do for you?

I understand the basic concept of Dependency Injection. Rather than have a lot of global state, you instead pass around what you need to the constructors of your various objects. But I don't understand how this concept can be applied to a framework? What does a Dependency Injection framework do for you and when should you use one? ...

Needed: File system interfaces and implementation in .NET

I write unit tests to my code, using Moq as a mocking framework. My code includes calls to the file system, using direct calls to System.IO classes. For instance, File.Exists(...) etc. I'd like to change that code to be more testable, so I should have an interface, say IFile, with a relevant method, say Exists(string path). I know I can ...