为程序集中的所有类型创建LinFu拦截器

我正在尝试为我的DAL程序集中的所有方法创建LinFu拦截器。虽然我可以这样做:
[Intercepts(typeof(IFirstRepository))]
[Intercepts(typeof(ISecondaryRepository))]
[Intercepts(typeof(IIAnotherRepository))]
public class DalInterceptor : IInterceptor, IInitialize
{
... 
}
每次将新的存储库添加到程序集时,都会变得非常混乱并需要手动更新。 有没有办法为程序集中的每种类型自动创建代理类? 更新: 我使用作者本人的建议(Laureano先生)更新了我的代理生成器,所以我现在有了这个:
Func<IServiceRequestResult, object> createProxy = request =>
{
    var proxyFactory = new ProxyFactory();
    DalInterceptor dalInterceptor = new DalLiteInterceptor();
    return proxyFactory.CreateProxy<object>(dalInterceptor);
};
拦截器像以前一样设置。我现在遇到的问题是代理对象不包含原始对象的构造函数和方法(我猜是因为我在泛型create方法中使用了对象)。 我是否只是将其转换回所需的类型,或者我做了一些根本错误的事情? 谢谢。     
已邀请:
看起来您正在尝试使用LinFu的IOC容器来拦截容器实例化的各种服务。事实证明,LinFu有一个名为ProxyInjector的内部类,它允许您决定应该拦截哪些服务以及应该如何创建每个服务实例的代理。这是示例代码:
Func<IServiceRequestResult, bool> shouldInterceptServiceInstance = request=>request.ServiceType.Name.EndsWith("Repository");

Func<IServiceRequestResult, object> createProxy = request =>
{
   // TODO: create your proxy instance here
   return yourProxy;
};

// Create the injector and attach it to the container so that you can selectively
// decide which instances should be proxied
var container = new ServiceContainer();
var injector = new ProxyInjector(shouldInterceptServiceInstance, createProxy);
container.PostProcessors.Add(injector);

// ...Do something with the container here
编辑:我刚刚修改了ProxyInjector类,以便它现在是一个公共类而不是LinFu中的内部类。尝试一下,让我知道这是否有帮助。     

要回复问题请先登录注册