Revisiting XML Configurations In Unity In the past I wrote a few tutorials about Unity application block. One of the things I wrote about was how to configure a Unity container using design time configuration. In this post I’m going to revisit that post and show you how the configurations changed (for the better) and are much more easier to work with in the current version of Unity (version 2). The Unity Configuration Section As in my previous post we will first start with a small example of Unity configuration section in order to understand...
Using the ControllerActivator in MVC 3 In the previous post I showed how to use the DependencyResolver in order to bring Dependency Injection behavior to a MVC 3 application. In this post I’ll show you how you can use the ControllerActivator in order to activate controllers using your own behavior. The IControllerActivator In MVC 3 beta a new interface was introduced – the IControllerActivator. This interface is an injection point in order to create our own behavior in order to activate controllers. That interface is discoverable using the dependency resolver. If you don’t implement the interface...
Dependency Injection in MVC 3 Was Made Easier In the past I wrote a post that showed how to implement Dependency Injection using Unity in ASP.NET MVC framework. This post revisits that post and shows how you can do the same thing easily in MVC 3. Pay attention that the supplied code is based on MVC 3 beta and may change in the future. The IDependencyResolver and DependencyResolver MVC 3 introduces a new interface – the IDependencyResolver. This interface enables service location by providing two methods: GetService(Type serviceType) – this method...
Index Pages on My Blog
Lately, I received an e-mail from a reader of my blog which included an advice to make an index for my post series. I took his advice and made 3 index pages for the following subjects:
ADO.NET Data Services
ADO.NET Entity Framework
Unity Application Block
These index pages will be updated frequently whenever a new tutorial post will be added. Also, I’m going to add more index pages in the future for more post series. Thanks Marcellus. Enjoy!
How To Use Unity Container In ASP.NET MVC Framework
In the past I wrote the post How To Use Unity Container In ASP.NET. In this post I’m going to explain how we can use Unity IoC container in ASP.NET MVC Framework.
Building The Container
As in the previous post the first thing to do is to build the container itself. I’ll use the same method I used in the previous post in order to persist the Unity container’s state during the application execution. The right place to put the Unity container is as part of the Global.asax file as a property of...
Dependency Injection From Theory to Practice With Unity Article Today my article, Dependency Injection From Theory to Practice With Unity, was published on the Hebrew MSDN site. The article describe what is dependency injection and then introduce the Unity application block. You can read the article here. You can read more Hebrew MSDN articles here. Enjoy.
Common Service Locator Library introduction Yesterday Glenn Block introduced a Common Service Locator library which is described as “a shared interface that applications and frameworks can reference in order to leverage IoC containers / service location mechanisms without taking hard dependencies”. The idea for the library is based on a post that Jeremy Miller wrote of having a shared interface ...
Using Unity Injection API
In some previous posts I explained how to use the Unity configuration section in dependency injection scenarios. In this post I’m going to show how to use some aspects of the Unity injection API.
Unity Injection API When you use Unity sometimes you want to inject dependencies in runtime and not in configuration files. The use of Unity injection API can help you do it very simple. In the Unity application block use the Microsoft.Practices.Unity namespace in order to use the injection API. All the classes that can be used to inject dependencies has...
Using Unity Container Hierarchies
In today’s post I’m going to explain why and how to use the Unity container hierarchies. As the subject suggest Unity application block supports nested containers and allow you to build containers hierarchies.
Why to Use Nested Containers There are two reasons to use a nested containers:
Control the scope of singleton object instances.
Register different mapping for specific types.
Controlling the Scope of Singleton Object Instances Singleton objects lifetime is managed by the Unity container. They are kept in scope as long as the container isn’t disposed. In order to enable the existence of two separate sets of...
Working With Generic Types In Unity Configuration Section
In my previous post about Unity I discussed about configuration files and how to configure Unity with them. I got a question in the subject of how to use generic types in the configuration files. This post will answer that question.
The Scenario I have an interface of IValidator which receives a generic type T.
public interface IValidator<T>
Also, I have a class Validator which receives a generic type T and implement the IValidator interface.
public class Validator<T> : IValidator<T>
#region IValidator<T> Members