首页 > 其他分享 >Enterprise Library 5 系列之1——Application Block的使用

Enterprise Library 5 系列之1——Application Block的使用

时间:2022-08-14 08:44:20浏览次数:57  
标签:Resolve Library Application Unity Block Enterprise var theContainer

Application Block的对象、原型(Facades)与工厂

Application Block

Non-static Instance or Factory

Caching

ICacheManager

Cryptography

CryptographyManager

Data Access

Database

Exception Handling

ExceptionManager

Logging

LogWriter

TraceManager

Security

ISecurityCacheProvider

IAuthorizationProvider

Validation

ValidatorFactory

ConfigurationValidatorFactory

AttributeValidatorFactory

ValidationAttributeValidatorFactory

 

服务定位器(Service Locator)

var writer = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();

var customerDb = EnterpriseLibraryContainer.Current.GetInstance<Database>("Customers");

 

访问容器

var theContainer = new UnityContainer() .AddNewExtension<EnterpriseLibraryCoreExtension>();

var writer = theContainer.Resolve<LogWriter>();

var customerDb = theContainer.Resolve<Database>("Customers");

 

需引用的程序集:

  • Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Unity
  • Microsoft.Practices.Unity

以上两种方法的优缺点,见https://docs.microsoft.com/en-us/previous-versions/msp-n-p/ff953191(v=pandp.50)

 

标签:Resolve,Library,Application,Unity,Block,Enterprise,var,theContainer
From: https://www.cnblogs.com/5x19/p/16584772.html

相关文章