具有属性的方法的Autofac ApiController过滤器

问题描述 投票:1回答:1

目标是使用.AsWebApiAuthorizationFilterFor<ApiController>(c => c.GetType()将少数Attr转换为来自Autofac的DI过滤器>

感觉就像我很接近,但是可能做错了,发现了很多关于Peram注射器的帖子,但这不是我想要在这里做的。

当前失败的尝试

       builder.RegisterType<SomeFilter>()
            .AsWebApiAuthorizationFilterFor<ApiController>(c => c.GetType()
                .GetMethods()
                .Where(m => m.GetCustomAttributes<SomeAttribute>().Any())
            )
            .InstancePerRequest();

目标:为具有特定属性的所有api控制器和/或控制器方法添加此过滤器

目标是使用.AsWebApiAuthorizationFilterFor (c => c.GetType()感觉很近,但是可能做错了,...

c# autofac autofac-configuration
1个回答
2
投票

AsWebApiAuthorizationFilterFor的第二个参数是一个动作选择器,用于选择一种为其创建过滤器的方法。

要应用条件注册,可以使用OnlyIf

© www.soinside.com 2019 - 2024. All rights reserved.