From 800f91db6713718d2e9fa42c00aa9222e644a780 Mon Sep 17 00:00:00 2001 From: maliming Date: Sun, 28 Aug 2022 15:47:57 +0800 Subject: [PATCH] Add `AbpPropertySelector`. --- .../AbpRegistrationBuilderExtensions.cs | 4 ++-- .../Volo/Abp/Autofac/AbpPropertySelector.cs | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 framework/src/Volo.Abp.Autofac/Volo/Abp/Autofac/AbpPropertySelector.cs diff --git a/framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs b/framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs index 2031cb5558..03084d8351 100644 --- a/framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs +++ b/framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Autofac.Core; using Autofac.Extras.DynamicProxy; +using Volo.Abp.Autofac; using Volo.Abp.Castle.DynamicProxy; using Volo.Abp.DependencyInjection; using Volo.Abp.Modularity; @@ -71,8 +72,7 @@ public static class AbpRegistrationBuilderExtensions if (moduleContainer.Modules.Any(m => m.Assembly == implementationType.Assembly) && implementationType.GetCustomAttributes(typeof(DisablePropertyInjectionAttribute), true).IsNullOrEmpty()) { - registrationBuilder = registrationBuilder.PropertiesAutowired((propertyInfo, _) => - propertyInfo.GetCustomAttributes(typeof(DisablePropertyInjectionAttribute), true).IsNullOrEmpty()); + registrationBuilder = registrationBuilder.PropertiesAutowired(new AbpPropertySelector(false)); } return registrationBuilder; diff --git a/framework/src/Volo.Abp.Autofac/Volo/Abp/Autofac/AbpPropertySelector.cs b/framework/src/Volo.Abp.Autofac/Volo/Abp/Autofac/AbpPropertySelector.cs new file mode 100644 index 0000000000..00d20e9bca --- /dev/null +++ b/framework/src/Volo.Abp.Autofac/Volo/Abp/Autofac/AbpPropertySelector.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; +using System.Reflection; +using Autofac.Core; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.Autofac; + +public class AbpPropertySelector : DefaultPropertySelector +{ + public AbpPropertySelector(bool preserveSetValues) + : base(preserveSetValues) + { + } + + public override bool InjectProperty(PropertyInfo propertyInfo, object instance) + { + return propertyInfo.GetCustomAttributes(typeof(DisablePropertyInjectionAttribute), true).IsNullOrEmpty() && + base.InjectProperty(propertyInfo, instance); + } + +}