Filter 框架支持2中 注入
作者:互联网
ServiceFilter 是利用ioc 容器获取实例
public IFilterMetadata CreateInstance(IServiceProvider serviceProvider) if (serviceProvider == null) { throw new ArgumentNullException(nameof(serviceProvider)) ; var filter = (IFilterMetadata)serviceProvider.GetRequiredService(ServiceType);if (filter is IFilterFactory filterFactory) filter = filterFactory.CreateInstance(serviceProvider) ; return filter;
}
typeFilter 是利用反射CreateInstance 创建对象实例 所以在标记特性的类型,serviceFileter 需要配置映射关系,而typeFilter 不需要的
标签:filter,typeFilter,框架,filterFactory,serviceProvider,CreateInstance,Filter,IFilter 来源: https://www.cnblogs.com/jasontarry/p/15408432.html