Browse Source

Add `AbpPropertySelector`.

pull/13844/head
maliming 4 years ago
parent
commit
800f91db67
  1. 4
      framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs
  2. 21
      framework/src/Volo.Abp.Autofac/Volo/Abp/Autofac/AbpPropertySelector.cs

4
framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Autofac.Core; using Autofac.Core;
using Autofac.Extras.DynamicProxy; using Autofac.Extras.DynamicProxy;
using Volo.Abp.Autofac;
using Volo.Abp.Castle.DynamicProxy; using Volo.Abp.Castle.DynamicProxy;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
@ -71,8 +72,7 @@ public static class AbpRegistrationBuilderExtensions
if (moduleContainer.Modules.Any(m => m.Assembly == implementationType.Assembly) && if (moduleContainer.Modules.Any(m => m.Assembly == implementationType.Assembly) &&
implementationType.GetCustomAttributes(typeof(DisablePropertyInjectionAttribute), true).IsNullOrEmpty()) implementationType.GetCustomAttributes(typeof(DisablePropertyInjectionAttribute), true).IsNullOrEmpty())
{ {
registrationBuilder = registrationBuilder.PropertiesAutowired((propertyInfo, _) => registrationBuilder = registrationBuilder.PropertiesAutowired(new AbpPropertySelector(false));
propertyInfo.GetCustomAttributes(typeof(DisablePropertyInjectionAttribute), true).IsNullOrEmpty());
} }
return registrationBuilder; return registrationBuilder;

21
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);
}
}
Loading…
Cancel
Save