Implement synchronization for object extensions.

pull/6342/head
Halil İbrahim Kalkan 5 years ago
parent 869bc26a02
commit cd4a7200f9

@ -1,16 +1,19 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using JetBrains.Annotations;
namespace Volo.Abp.ObjectExtending.Modularity
{
public static class ModuleExtensionConfigurationHelper
{
private static object SyncLock = new object();
public static void ApplyEntityConfigurationToEntity(
string moduleName,
string entityName,
Type entityType)
{
lock (SyncLock)
{
foreach (var propertyConfig in GetPropertyConfigurations(moduleName, entityName))
{
@ -21,6 +24,7 @@ namespace Volo.Abp.ObjectExtending.Modularity
}
}
}
}
public static void ApplyEntityConfigurationToApi(
string moduleName,
@ -28,6 +32,8 @@ namespace Volo.Abp.ObjectExtending.Modularity
Type[] getApiTypes = null,
Type[] createApiTypes = null,
Type[] updateApiTypes = null)
{
lock (SyncLock)
{
foreach (var propertyConfig in GetPropertyConfigurations(moduleName, objectName))
{
@ -55,12 +61,15 @@ namespace Volo.Abp.ObjectExtending.Modularity
}
}
}
}
public static void ApplyEntityConfigurationToUi(
string moduleName,
string entityName,
Type[] createFormTypes = null,
Type[] editFormTypes = null)
{
lock (SyncLock)
{
foreach (var propertyConfig in GetPropertyConfigurations(moduleName, entityName))
{
@ -82,6 +91,7 @@ namespace Volo.Abp.ObjectExtending.Modularity
}
}
}
}
public static void ApplyEntityConfigurations(
string moduleName,
@ -92,6 +102,8 @@ namespace Volo.Abp.ObjectExtending.Modularity
Type[] getApiTypes = null,
Type[] createApiTypes = null,
Type[] updateApiTypes = null)
{
lock (SyncLock)
{
if (entityType != null)
{
@ -117,11 +129,14 @@ namespace Volo.Abp.ObjectExtending.Modularity
editFormTypes: editFormTypes
);
}
}
[NotNull]
public static IEnumerable<ExtensionPropertyConfiguration> GetPropertyConfigurations(
string moduleName,
string entityName)
{
lock (SyncLock)
{
var moduleConfig = ObjectExtensionManager.Instance.Modules().GetOrDefault(moduleName);
if (moduleConfig == null)
@ -137,10 +152,13 @@ namespace Volo.Abp.ObjectExtending.Modularity
return objectConfig.GetProperties();
}
}
public static void ApplyPropertyConfigurationToTypes(
ExtensionPropertyConfiguration propertyConfig,
Type[] types)
{
lock (SyncLock)
{
ObjectExtensionManager.Instance
.AddOrUpdateProperty(
@ -160,4 +178,5 @@ namespace Volo.Abp.ObjectExtending.Modularity
);
}
}
}
}

@ -1,4 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using JetBrains.Annotations;
@ -12,10 +13,10 @@ namespace Volo.Abp.ObjectExtending
public Type Type { get; }
[NotNull]
protected Dictionary<string, ObjectExtensionPropertyInfo> Properties { get; }
protected ConcurrentDictionary<string, ObjectExtensionPropertyInfo> Properties { get; }
[NotNull]
public Dictionary<object, object> Configuration { get; }
public ConcurrentDictionary<object, object> Configuration { get; }
[NotNull]
public List<Action<ObjectExtensionValidationContext>> Validators { get; }
@ -23,8 +24,8 @@ namespace Volo.Abp.ObjectExtending
public ObjectExtensionInfo([NotNull] Type type)
{
Type = Check.AssignableTo<IHasExtraProperties>(type, nameof(type));
Properties = new Dictionary<string, ObjectExtensionPropertyInfo>();
Configuration = new Dictionary<object, object>();
Properties = new ConcurrentDictionary<string, ObjectExtensionPropertyInfo>();
Configuration = new ConcurrentDictionary<object, object>();
Validators = new List<Action<ObjectExtensionValidationContext>>();
}
@ -56,7 +57,7 @@ namespace Volo.Abp.ObjectExtending
var propertyInfo = Properties.GetOrAdd(
propertyName,
() => new ObjectExtensionPropertyInfo(this, propertyType, propertyName)
_ => new ObjectExtensionPropertyInfo(this, propertyType, propertyName)
);
configureAction?.Invoke(propertyInfo);

@ -14,11 +14,11 @@ namespace Volo.Abp.ObjectExtending
[NotNull]
public ConcurrentDictionary<object, object> Configuration { get; }
protected Dictionary<Type, ObjectExtensionInfo> ObjectsExtensions { get; }
protected ConcurrentDictionary<Type, ObjectExtensionInfo> ObjectsExtensions { get; }
protected internal ObjectExtensionManager()
{
ObjectsExtensions = new Dictionary<Type, ObjectExtensionInfo>();
ObjectsExtensions = new ConcurrentDictionary<Type, ObjectExtensionInfo>();
Configuration = new ConcurrentDictionary<object, object>();
}
@ -54,7 +54,7 @@ namespace Volo.Abp.ObjectExtending
var extensionInfo = ObjectsExtensions.GetOrAdd(
type,
() => new ObjectExtensionInfo(type)
_ => new ObjectExtensionInfo(type)
);
configureAction?.Invoke(extensionInfo);

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using JetBrains.Annotations;
using Volo.Abp.Localization;
using Volo.Abp.ObjectExtending.Modularity;

Loading…
Cancel
Save