当我使用派生类时,我遇到了一种情况,即策略注入不再起作用。
所涉及的类看起来像这样(基本上是一个接口、一个抽象基类和一个实现类):
public interface IRepository<T>
{
    void Create(T iItem);
}
public abstract class ElmtRepository<T> : IRepository<T>
{
    protected List<T> Items { get; set; }
    public ElmtRepository()
    {
        Items = new List<T>();
    }
    public void Create(T iItem)
    {
        Items.Add(iItem);
    }
}
public class AcctPgmRepository : ElmtRepository<AcctPgm>
{
}
配置如下所示:
  <container>
    <extension type="Interception"/>
    <register type="IRepository[AcctPgm]" mapTo="AcctPgmRepository">
      <interceptor type="InterfaceInterceptor"/>
      <interceptionBehavior type="PolicyInjectionBehavior"/>
    </register>
    <interception>
      <policy name="policy-create">
        <matchingRule name="create-rule1" type="TypeMatchingRule">
          <constructor>
            <param name="typeName">
              <value value="AcctPgmRepository"/>
            </param>
          </constructor>
        </matchingRule>
        <matchingRule name="create-rule2" type="MemberNameMatchingRule">
          <constructor>
            <param name="namesToMatch">
              <array type="string[]">
                <value value="Create"/>
              </array>
            </param>
          </constructor>
        </matchingRule>
        <callHandler name="create-handler1" type="AcctPgmAuthorizationHandler">
          <lifetime type="singleton"/>
          <constructor>
            <param name="allowedRoles">
              <array type="string[]">
                <value value="GroupController"/>
              </array>
            </param>
          </constructor>
        </callHandler>
      </policy>
    </interception>
  </container>
如果我删除 ElmtRepository 基类,它会按预期工作。使用基类,注入不会发生。没有错误消息,但也没有策略。即使我在派生类中实现 Create() 方法,也会发生这种情况。
有没有办法让这种类层次结构与 Unity 策略注入一起工作?
谢谢,吉姆