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

时间:2016-03-01 12:12:24

标签: castle-windsor

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

在拦截器内部,我看到IRepositoryProxy basetype是Object而不是Repository

例如:我解析IRepository并致电GetFunctionalityPurposes, 我想要的是调用GetAllFunctionalityPurposes也被缓存/代理。

这不起作用,因为方法是在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;
}

1 个答案:

答案 0 :(得分:0)

我调查了https://github.com/castleproject/Windsor/blob/master/src/Castle.Windsor/Windsor/Proxy/DefaultProxyFactory.cs#L110,我已经轻松完成了注册:Dim strCache() As String = Split(fileReader.ReadLine(), ";") Dim repStrX = strCache(intValXAxis - 1).Replace(",","G").Replace(".",",").Replace("G",".") Dim repStrY = strCache(intValYAxis - 1).Replace(",","G").Replace(".",",").Replace("G",".") ChartSeries(i).Points.AddXY(repStrX , repStrY)

注意。通过ServiceSelf()调用,这实际上会切换基于类的代理