Browse Source
Merge pull request #6054 from abpframework/maliming/Enhancement-5952
Enhance the function of PR 5952.
pull/6058/head
Halil İbrahim Kalkan
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with
3 additions and
41 deletions
-
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/MvcCoreBuilderExtensions.cs
-
framework/src/Volo.Abp.Auditing/Volo.Abp.Auditing.csproj
-
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/EntityHelper.cs
-
framework/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/JsonConverters/EntityJsonConverter.cs
-
modules/docs/src/Volo.Docs.Domain.Shared/Volo.Docs.Domain.Shared.csproj
|
|
@ -23,7 +23,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Json |
|
|
return new SystemTextJsonInputFormatter(jsonOptions.Value, logger); |
|
|
return new SystemTextJsonInputFormatter(jsonOptions.Value, logger); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
builder.Services.AddTransient<DefaultObjectPoolProvider>(); |
|
|
builder.Services.TryAddTransient<DefaultObjectPoolProvider>(); |
|
|
//NewtonsoftJsonInputFormatter
|
|
|
//NewtonsoftJsonInputFormatter
|
|
|
builder.Services.AddTransient(provider => |
|
|
builder.Services.AddTransient(provider => |
|
|
{ |
|
|
{ |
|
|
|
|
|
@ -23,8 +23,4 @@ |
|
|
<ProjectReference Include="..\Volo.Abp.Timing\Volo.Abp.Timing.csproj" /> |
|
|
<ProjectReference Include="..\Volo.Abp.Timing\Volo.Abp.Timing.csproj" /> |
|
|
</ItemGroup> |
|
|
</ItemGroup> |
|
|
|
|
|
|
|
|
<ItemGroup> |
|
|
|
|
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> |
|
|
|
|
|
</ItemGroup> |
|
|
|
|
|
|
|
|
|
|
|
</Project> |
|
|
</Project> |
|
|
|
|
|
@ -246,36 +246,5 @@ namespace Volo.Abp.Domain.Entities |
|
|
? new Type[] { typeof(DisableIdGenerationAttribute) } |
|
|
? new Type[] { typeof(DisableIdGenerationAttribute) } |
|
|
: new Type[] { }); |
|
|
: new Type[] { }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static void TrySetId<TKey>( |
|
|
|
|
|
object entity, |
|
|
|
|
|
TKey id, |
|
|
|
|
|
bool checkForDisableIdGenerationAttribute = false) |
|
|
|
|
|
{ |
|
|
|
|
|
var property = CachedIdProperties.GetOrAdd( |
|
|
|
|
|
$"{entity.GetType().FullName}-{checkForDisableIdGenerationAttribute}", () => |
|
|
|
|
|
{ |
|
|
|
|
|
var idProperty = entity |
|
|
|
|
|
.GetType() |
|
|
|
|
|
.GetProperties() |
|
|
|
|
|
.FirstOrDefault(x => x.Name == nameof(IEntity<object>.Id) && |
|
|
|
|
|
x.GetSetMethod(true) != null); |
|
|
|
|
|
|
|
|
|
|
|
if (idProperty == null) |
|
|
|
|
|
{ |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (checkForDisableIdGenerationAttribute && |
|
|
|
|
|
idProperty.IsDefined(typeof(DisableIdGenerationAttribute), true)) |
|
|
|
|
|
{ |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return idProperty; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
property?.SetValue(entity, id); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
@ -6,6 +6,7 @@ using Volo.Abp.Domain.Entities; |
|
|
namespace Volo.Abp.MemoryDb.JsonConverters |
|
|
namespace Volo.Abp.MemoryDb.JsonConverters |
|
|
{ |
|
|
{ |
|
|
public class EntityJsonConverter<TEntity, TKey> : JsonConverter<TEntity> |
|
|
public class EntityJsonConverter<TEntity, TKey> : JsonConverter<TEntity> |
|
|
|
|
|
where TEntity : IEntity<TKey> |
|
|
{ |
|
|
{ |
|
|
public override TEntity Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
|
|
public override TEntity Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
|
|
{ |
|
|
{ |
|
|
@ -16,7 +17,7 @@ namespace Volo.Abp.MemoryDb.JsonConverters |
|
|
var id = JsonSerializer.Deserialize<TKey>(idJsonElement.GetRawText()); |
|
|
var id = JsonSerializer.Deserialize<TKey>(idJsonElement.GetRawText()); |
|
|
if (id != null) |
|
|
if (id != null) |
|
|
{ |
|
|
{ |
|
|
EntityHelper.TrySetId(entity, id); |
|
|
EntityHelper.TrySetId(entity, () => id); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return entity; |
|
|
return entity; |
|
|
|
|
|
@ -13,9 +13,5 @@ |
|
|
<ItemGroup> |
|
|
<ItemGroup> |
|
|
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Localization\Volo.Abp.Localization.csproj" /> |
|
|
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Localization\Volo.Abp.Localization.csproj" /> |
|
|
</ItemGroup> |
|
|
</ItemGroup> |
|
|
|
|
|
|
|
|
<ItemGroup> |
|
|
|
|
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> |
|
|
|
|
|
</ItemGroup> |
|
|
|
|
|
|
|
|
|
|
|
</Project> |
|
|
</Project> |
|
|
|