Autofac正式发布2.1版

Nicholas Blumhardt经过了2年多的开发,设计和试验,Autofac发布了第二版,针对1.4版本进行了重组,提供了更好的开发体验,你可以到这里下载正式的版本。

2.1版本也带来许多新特性:

  1. 组件发现:Autofac 2可以从一个程序集的注册类型设置根据用户指定的规则:

    var dataAccess = Assembly.GetExecutingAssembly();
    builder.RegisterAssemblyTypes(dataAccess)
        .Where(t => t.Name.EndsWith("Repository"))
        .AsImplementedInterfaces();

    RegisterAssemblyTypes方法将Repository模式的数据访问接口类都注册了,语法非常的简单。

  2. 类型关系:Autofac通过自动支持小型,有重点,强类型的包装,来表达动态的依赖关系。类型关系如下:
    RelationshipAdapter TypeMeaning
    A needs a BNoneDependency
    A needs a B at some point in the futureLazy<B>Delayed instantiation
    A needs a B until some point in the futureOwned<B>Controlled lifetime
    A needs to create instances of BFunc<B>Dynamic instantiation
    A provides parameters of types X and Y to BFunc<X,Y,B>Parameterisation
    A needs all the kinds of BIEnumerable<B>Enumeration
    A needs to know X about B before using itMeta<T> and Meta<B,X>Metadata interrogation
       具体参看文章The Relationship Zoo.
  3. 组件元数据:.NET 4版本的Autofac 2.1支持类似于Managed Extensibility Framework (MEF)的功能。.NET 3.5(以及4.0)版本的提供了一个弱类型的Meta<T>
  4. 集成Managed Extensibility Framework (MEF),具体内容参看Autofac MEF integration wiki page,有一篇博客Hosting MEF Extensions in an IoC Container对这个架构进行了深入的讨论。

2.1版本不仅带来了许多新特性,而且对1.4版本也作了很大的改进:

 

参考文章

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值