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.
...
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...
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...
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...
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 ...
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...
I'm just trying to understand where the label 'container' came from. Anyone know?
Seems like many things could be called 'containers'.
...
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...
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...
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"?
...
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...
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...
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 ...
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 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...
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...
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 ...
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...
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?
...
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 ...