Introduction to dependency injection with unityContainer
来源:互联网 发布:淘宝直通车有必要开吗 编辑:程序博客网 时间:2024/06/05 13:09
/* By Dylan SUN */
This article is just a simple introduction to unityContainer.
If you have already used unityContainer as a dependency injection or IoC (Inversion of control) library, this article is not for you.
As you know, dependency injection is a design pattern to prevent the code coupling.
For example, you access class CA’s method MA in several places in your application. If one day you need to use class CB instead of class CA. You need to replace all the code referencing class CA with class CB.
But if you use dependency injection, you just need to register the interface and its implementation class once. You can resolve the interface when you need to access method CA.
Here is an sample usage of unityContainer:
Firstly, create an instance of UnityContainer.
//register interface and its implementationIUnityContainer container = new UnityContainer();
Register the interface and its implementation class.
container.RegisterType<IConfigurationReader, ConfigurationReader>();
Resolve the interface.
var configurationReader = container.Resolve<IConfigurationReader>();
Access to method :
var value = configurationReader.GetAppSettings("hello");
In this way, you won’t need to create any instance of a specific class. The code is more maintainable.
I hope you find this article helpful!
- Introduction to dependency injection with unityContainer
- SCSF - Part 3 Introduction to Dependency Injection
- Dependency injection with Flex
- Dependency Injection with Autofac
- ASP.NET 5 Dependency Injection with Autofac
- Dependency Injection
- Dependency Injection
- Dependency Injection
- Dependency Injection
- Inversion of Control and Dependency Injection with Castle Windsor Container
- how to use MEF do DI(DEPENDENCY INJECTION )
- Introduction to XSTL with Delphi
- Introduction to programming with OpenCV
- Introduction to programming with OpenCV
- Introduction to programming with OpenCV
- Introduction to programming with OpenCV
- IOC和Dependency Injection
- IOC和Dependency Injection
- 机器学习基石——第11-12讲.Linear Models for Classification
- 机器学习基石——第13-14讲.Hazard of Overfitting
- 图片转成base64串
- macos 隐藏显示文件
- Java学习路线图
- Introduction to dependency injection with unityContainer
- Sass map详解
- 在网页中使用Applet的标签详解
- 如何编写绑定端口shellcode
- 什么是Java Plug-in
- IE中object标签
- 寻找 黑帽 代做寄生虫
- Just4Fun - PreIncrement vs PostIncrement
- 2015年2月7日--2月15日(共30小时,剩3870小时)