在我的接口的每次注册中使用WithAttributeFilter()有什么缺点



我正在使用一条规则来注册我的解决方案中的所有接口:

public void RegisterDefaultNamingConventionInterfacesForAssembly(string assembly,
string namespaceFilter)
{
// Default Rule => Foo : IFoo
_builder.RegisterAssemblyTypes(Assembly.Load(assembly))
.Where(t =>
{
var existImplementation = t.Namespace != null && t.Namespace.Contains(namespaceFilter) &&
t.GetInterfaces().FirstOrDefault(i => i.Name == "I" + t.Name) != null;
return existImplementation;
})
.As(t => { return t.GetInterfaces().FirstOrDefault(i => i.Name == "I" + t.Name); })
.WithAttributeFiltering();
;
}

中的某些类(不是全部(使用基于ParameterFilterAttribute的自定义属性。这就是为什么我需要使用WithAttributeFilter((注册。

使用WithAttributeFilter((注册每个类有什么缺点,即使其中许多类没有使用自定义的ParameterFilterAttribute?

您必须选择使用WithAttributeFiltering的原因是这会带来性能成本。每次在解析操作中使用过滤时,都必须完成执行过滤的工作——否则就不需要执行这些工作。如果您正在构建一个小型系统或不是性能密集型的系统,您可能不会注意到差异。如果你正在构建性能很重要的东西,那么在需要的东西上只选择将帮助你获得更好的性能。

相关内容

  • 没有找到相关文章

最新更新