CodeKicks.com
Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Tuesday, April 22, 2008

Download and use Unity Application Block

Overview
The Unity Application Block addresses the issues in component-based software engineering. It provides simplified object creation, especially for hierarchical object structures and dependencies. For example, an object that processes customer information may depend on other objects that access the data store, validate the information, and check that the user is authorized to perform updates. Dependency injection techniques can ensure that the customer class correctly instantiates and populates all of these objects, especially where the dependencies may be abstract. It can read configuration information from standard configuration systems, such as XML files, and use it to configure the container. It supports custom container extensions that developers can implement
Unity Application Block exposes two methods.
RegisterType: This method registers a type with the container.
RegisterInstance: This method registers with the container an existing instance of a type that you specify, with the lifetime that you specify.

Using Unity Application Block
Using Register Type method

IUnityContainer myContainer = new UnityContainer();
myContainer.RegisterType();
IMyService myServiceInstance = myContainer.Resolve();

Using Register Instance method

IUnityContainer myContainer = new UnityContainer();
LoggingService myExistingObject = new LoggingService();
myContainer.RegisterInstance(myExistingObject);
IMyService myServiceInstance = myContainer.Resolve();
Download Unity Application Block at Read More at

Post a Comment

Aditya said...

It is good see following the Dependency injection in this.

Thanks for the post.