在具体 class 中调用代理方法的正确方法是什么?

What is the proper way to call proxied method inside concrete class?

例如我有 IRepository,由 Repository 和一些拦截器实现。

在拦截器内部,我看到 IRepositoryProxy 基本类型是 Object 而不是 Repository.

例如:我解析IRepository并调用GetFunctionalityPurposes, 我想要的是对 GetAllFunctionalityPurposes 的调用也是 cached/proxied.

这不起作用,因为这些方法是在 Repository 而不是 IRepositoryProxy 中调用的。

IRepository

FunctionalityPurpose[] GetFunctionalityPurposes();
FunctionalityPurpose[] GetAllFunctionalityPurposes()

存储库

[Cached("Tender")]
public virtual FunctionalityPurpose[] GetFunctionalityPurposes()
{
    var model = GetAllFunctionalityPurposes()
        .Where(r => !r.IsHidden && !r.GroupId.HasValue);

    return model;
}

[Cached("Tender", "FunctionalityPurpose")]
public virtual FunctionalityPurpose[] GetAllFunctionalityPurposes()
{
    var model = UnitOfWork.GetSet<Model>().Select(f => f.FunctionalityPurpose)
        .Distinct().OrderBy(r => r.Id).ToArray();

    return model;
}

我调查了 https://github.com/castleproject/Windsor/blob/master/src/Castle.Windsor/Windsor/Proxy/DefaultProxyFactory.cs#L110 并以简单的方式完成了注册:container.Register(Classes.FromThisAssembly().BasedOn(typeof(IRepositoryBase<,>)) .WithServiceAllInterfaces().WithServiceSelf().LifestyleTransient());

注意 .WithServiceSelf() 调用,这实际上切换了基于 class 的代理