【问题标题】:Is it possible to dynamically inject the attribute using IoC like Ninject or other IoC?是否可以使用 IoC(如 Ninject 或其他 IoC)动态注入属性?
【发布时间】:2009-01-09 03:52:44
【问题描述】:

我是extending my Object Property Value Diff,但我意识到如果一个对象有太多属性,我可能不想全部区分它们。所以我想出了

public class IgnorePropertyDiffAttribute : System.Attribute
{
}

以便我可以标记我希望差异忽略的属性。但是我不想用 [IgnorePropertyDiff] 污染我的域对象。

public class Role
{
    [IgnorePropertyDiff]
    public String Description { set; get; }
    public Double Salary { set; get; }
    public Boolean HasBonus { set; get; }
}

我的问题是,是否可以使用 IoC(如 Ninject 或其他 IoC)动态注入 [IgnorePropertyDiff]?如果我听起来像个白痴,请执行我,因为我只是一个初级中级 c# 开发人员。提前致谢。

【问题讨论】:

    标签: c# reflection dependency-injection inversion-of-control attributes


    【解决方案1】:

    属性是编译时特性,所以不能:您不能使用 IoC 添加它们(或针对它们设置值)。

    【讨论】:

      猜你喜欢
      • 2011-03-09
      • 1970-01-01
      • 2012-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多