Unity 开发和配置简介

前端之家收集整理的这篇文章主要介绍了Unity 开发和配置简介前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  
  
{ return " my sql connection "; } } public class MSsqlHelp : sqlHelp { override string sqlConnection() { ms sql connection "; } } class OraclesqlHelp : sqlHelp { oracle sql connection "; } }
app.config配置
  
  
<? xml version="1.0" encoding="utf-8" ?> < configuration > configSections section name ="unity" type ="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,Microsoft.Practices.Unity.Configuration" /> </ unity xmlns ="http://schemas.microsoft.com/practices/2010/unity" > container > register type ="sqlHelp,New_Code" mapTo ="MysqLHelp,New_Code" > lifetime ="singleton" /> register > unity > >
实现代码
  
  
void Main() { IUnityContainer container = new UnityContainer(); UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection( unity "); section.Containers.Default.Configure(container); sqlHelp sqlHelp = container.Resolve<sqlHelp>(); Console.WriteLine(sqlHelp.sqlConnection()); }

运行结果:

my sql connection

猜你在找的设计模式相关文章