Enterprise Library 5.0 研究 <1> 认识Enterprise Library 5.0

         微软刚发布了Enterprise Library 5.0,相对于4.x来说,里面有太多的亮点。也因为这些亮点,笔者才有了去学习和了解5.0的欲望。

 

        <什么是Enterprise Library>:根据微软的定义,Enterprise Library 是由若干应用模块和核心基础组件组成的,这些模块和组件都是可重用的并且可以帮助程序员去解决企业级开发中的通用性问题。诚然,在企业开发中,缓存、加密、数据库访问、异常处理、日志、安全、验证等问题,都是必然会遇到的问题。但是长久以来,微软并未提供官方性的指导;直到Enterprise Library的出现,我们看到了希望,并且随着Enterprise Library的版本更新,我们发现里面的处理机制也越来越成熟。这对所有的.net程序员和架构师来说,都是一个福音,不过Enterprise Library在国内并没有看到大规模展开使用的迹象,这不能不说是一种遗憾。

 

        <Enterprise Library 5.0 有了什么>:在Enterprise Library 5.0里面,我们最直观地可以看到的是有了一个可视化的配置工具,在这里所有的组件的属性都可以进行拖拉式的配置。在这里配置添加的组件,都可以通过依赖注入(IOC)到应用程序中供调用。这里我们可以联想到spring,而微软通过统一生命周期的方式去管理通用型组件,也是非常有想法的。

         看看这句话:"In this release of Enterprise Library, the underlying technique for creating objects uses a single dependency injection container; withUnity as the default container. It fully encompasses the move to using dependency injection techniques through Unity to instantiate objects. You can use the container to generate instances of Enterprise Library objects and inject them into other objects. " 从这里我们可以看到Unity作为一个单例的依赖注入容器的定义。而Object-Builder,这个低级别的注入机制,也在这个版本里被融入到Unity,因此我们再也不用引用或分配Object Builder assembly在项目中。关于Unity具体是如何运作的,我们在以后的文章中再来展开深入的研究。

         还有,从发布包里,我们可以看到Enterprise Library 5.0提供了VS 2008和VS 2010的两个入口,并且提供了非常多的Enterprise Library测试代码以及源代码。这个有时间的话也可以在以后再继续研究。

         然后,除了Cryptography Application Block 和 Security Application Block 没有任何调整,其他的组件或多或少都有一定的改变。

 

        <Enterprise Library 5.0 能用在哪些地方?>:在很多企业级应用必须的相同需求下,它提供了很丰富的解决之道;它有非常好的扩展性,如果你要开发自定义组件,它提供一个基础;整个Library下面的所有组件都是独立的,如果只需要使用其中一个的话并不需要加载所有包;等等。

 

         总之,以上这些内容仅仅是对Enterprise Library 5.0一个最基本的介绍,在以后我会对Enterprise Library 5.0里面的各项组件开展一些更为详细的研究和介绍。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 .NET Core 中使用 Enterprise Library,需要执行以下步骤: 1. 安装 NuGet 包:在项目中安装 Enterprise Library 的 NuGet 包。在 Visual Studio 中,右键单击项目并选择“Manage NuGet Packages”,然后搜索“EnterpriseLibrary”并安装。 2. 添加配置文件:在项目中添加一个名为“app.config”的配置文件,并将以下代码添加到文件中: ``` <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" /> </configSections> <enterpriseLibrary.ConfigurationSource selectedSource="File Configuration Source"> <sources> <add name="File Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" filePath=".\App.config" /> </sources> <redirectSections> <section name="loggingConfiguration" sourceName="File Configuration Source" /> </redirectSections> </enterpriseLibrary.ConfigurationSource> <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General"> <listeners> <add name="Rolling Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" fileName="C:\logs\myapp.log" footer="--------------------------" formatter="Text Formatter" header="--------------------------" rollFileExistsBehavior="Increment" rollInterval="Day" rollSizeKB="1024" timeStampPattern="yyyy-MM-dd" /> </listeners> <formatters> <add name="Text Formatter" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" template="{timestamp} [{category}] {message}" /> </formatters> <categorySources> <add switchValue="All" name="General"> <listeners> <add name="Rolling Flat File Trace Listener" /> </listeners> </add> </categorySources> </loggingConfiguration> </configuration> ``` 这个配置文件包含一个名为“Rolling Flat File Trace Listener”的日志记录器,它将日志记录到文件中。你可以根据自己的需要更改此配置。 3. 创建 Enterprise Library 实例:在代码中创建 Enterprise Library 实例,并使用它来记录日志。以下是一个示例: ``` using Microsoft.Practices.EnterpriseLibrary.Common.Configuration; using Microsoft.Practices.EnterpriseLibrary.Logging; ILogger logger = EnterpriseLibraryContainer.Current.GetInstance<ILogger>(); logger.Write("Hello, world!"); ``` 这将使用配置文件中指定的日志记录器记录一条消息。 希望这可以帮助你配置 Enterprise Library 在 .NET Core 中运行。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值