比较6个.NET控制反转(DI/IoC)框架

  1. 授权与程序大小
    框架版本授权最少dll引用大小(KB)
    CastleRC3Apache  2 2192
    Unity1.1MS-PL 2120
    Ninject1.0Apache 2 1
    (2 : autowiring)
    147 (154)
    Autofac1.2.7MIT 1110
    StructureMap2.4.9.0Apache  2 1164
    Spring.Net1.1.2Apache  2 2-3728
  2. 配置
    框架Fluent registration 自动注册使用Attribute使用XML
    Castlein trunk only有限, 将被废除支持, 非必须支持, 非必须
    Unityyes不支持支持, 非必须支持, 非必须
    Ninjectyes 支持支持, 非必须不支持, 可实现
    Autofacyes在网站上以范例提供不支持, 不需要支持, 非必须
    StructureMapyes 支持支持, 非必须支持, 非必须
    Spring.Netmethod chaining only不支持不包含, 可实现, 下个版本支持支持, 非必须, 推荐
  3. 基本注入与自动连线
    框架属性注入构造器注入多个构造器循环依赖
    Castle支持yesmost resolvable parameters meaningful error
    Unity需要代码,特性或XML, mandatory dependencyyeshardcoded, attributed or most parametersstack overflow
    Ninject需要Attribute, automatic with official extensionyesattributed or default, most resolvable parameters with official extensionstack overflow
    Autofacyes (opt-in)yesmost resolvable parameters meaningful error
    StructureMap需要Attribute或XML, mandatory dependencyyesattributed or most parametersstack overflow
    Spring.Netyes (opt-in)yeshardcoded signature, default, if no default then most resolvable parametersstack overflow
  4. 生命周期

    框架单例短暂的其它/自定义自定义实例
    Castleyesyesyes, pluggable 支持
    Unityyesyesyes, pluggable 支持
    Ninjectyesyes yes, pluggable 支持
    Autofacyesyesyes, pluggable 支持
    StructureMapyesyesyes, pluggable支持, 支持prototypes (cloning)
    Spring.Netyesyesyes, pluggable supported

  5. 高级resolution
    框架Open generics injectionList injectionUnregistered resolution
    Castlesupportednot included, implementable (but hard to implement correctly)not supported, no good workarounds
    Unitysupportednot included, probably implementableyes
    Ninjectsupportednot included, probably implementableyes
    Autofac supported, requires explicit registrationnot included, probably implementablerequires special opt-in
    StructureMapsupportedworks at least for arrays, haven't found documentation anywhereyes
    Spring.Netnot supported, no easy workaround documented, not working in current version (bug)either not supported or not easy
  6. 总况
    框架Auto-mocking特殊功能特殊问题
    Castlenot included, implementable rare releases, some major features trunk-only for some time
    Unitynot included, implementable no
    Ninjectnot included, probably implementablecontextual bindingsproblems referencing under .NET 3.5 (ExtensionAttribute defined twice)
    Autofacin Contrib, linked from home page (NMock2)container hierarchies/tagging, expression constructorsno
    StructureMapincluded (NMock) documentation/samples a bit obscuring the existence of non-static API
    Spring.Netnot included, probably implementable complex registration API, XML (verbose) encouraged
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值