【问题标题】:Dependency injection into a static class [duplicate]依赖注入到静态类中[重复]
【发布时间】:2011-10-03 08:52:05
【问题描述】:

可能重复:
Configure Property of a static class via spring .net

我想使用 spring .net 为静态类中的属性注入值。 代码sn-p:

Public static Abc
{
Public static IInterface IInterface{get;set;}
}

这里我想通过 spring .net 配置在 Abc staic 类中注入 IInterface 值。

【问题讨论】:

    标签: c#-4.0 spring.net static-class


    【解决方案1】:

    我怀疑你是否能做到。

    静态类不能很好地与依赖注入一起工作。

    最好将类创建为普通类并将其设置为容器中的单例。我很确定 spring.net 会允许这样做..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-08
      • 1970-01-01
      • 2011-11-16
      • 2017-05-02
      • 1970-01-01
      • 2015-06-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多