Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="10.0.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyModel" Version="10.0.1" />
<PackageVersion Include="AutoMapper" Version="14.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="5.0.0" />
<PackageVersion Include="MediatR" Version="12.5.0" />
Expand Down Expand Up @@ -59,10 +58,11 @@
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="10.0.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="MSTest.TestAdapter" Version="4.0.2" />
<PackageVersion Include="MSTest.TestFramework" Version="4.0.2" />
<PackageVersion Include="MSTest.TestAdapter" Version="4.1.0" />
<PackageVersion Include="MSTest.TestFramework" Version="4.1.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
<PackageVersion Include="NUnit" Version="4.4.0" />
<PackageVersion Include="Verify.MSTest" Version="31.13.5" />
<PackageVersion Include="Aspire.Hosting.AppHost" Version="13.1.0" />
<PackageVersion Include="Aspire.Hosting.MongoDB" Version="13.1.0" />
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="10.1.0" />
Expand Down
41 changes: 41 additions & 0 deletions GrandNode.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Grand.Web.Common", "src\Web
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Grand.Infrastructure", "src\Core\Grand.Infrastructure\Grand.Infrastructure.csproj", "{34A46D97-5996-46B3-BDCA-631EDAA0E210}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Grand.Mapping", "src\Core\Grand.Mapping\Grand.Mapping.csproj", "{D4E5F6A7-B8C9-4D0E-A236-B4C5D6E7F8A9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{F6F48227-B3C5-4A51-B33F-FF9AD96352DB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Authentication.Facebook", "src\Plugins\Authentication.Facebook\Authentication.Facebook.csproj", "{BA4579AF-9C20-477A-891B-926968B11C68}"
Expand Down Expand Up @@ -145,6 +147,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.ServiceDefaults", "s
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Grand.Web.AdminShared", "src\Web\Grand.Web.AdminShared\Grand.Web.AdminShared.csproj", "{12C4A556-E62E-4EC0-BCD9-E9D4E1F3D430}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{827E0CD3-B72D-47B6-A68D-7590B98EB39B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Grand.Mapping.Tests", "src\Tests\Grand.Mapping.Tests\Grand.Mapping.Tests.csproj", "{396E6929-5365-4116-8AA8-DF5327247798}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Web", "Web", "{03997797-E7F5-0643-168D-B8EA7178C2FE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Modules", "Modules", "{EC447DCF-ABFA-6E24-52A5-D7FD48A5C558}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Business", "Business", "{CC1F4FA2-92F2-BA4B-815B-7EC2CBBCCF50}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -323,6 +335,18 @@ Global
{34A46D97-5996-46B3-BDCA-631EDAA0E210}.Release|x64.Build.0 = Release|Any CPU
{34A46D97-5996-46B3-BDCA-631EDAA0E210}.Release|x86.ActiveCfg = Release|Any CPU
{34A46D97-5996-46B3-BDCA-631EDAA0E210}.Release|x86.Build.0 = Release|Any CPU
{D4E5F6A7-B8C9-4D0E-A236-B4C5D6E7F8A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4E5F6A7-B8C9-4D0E-A236-B4C5D6E7F8A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4E5F6A7-B8C9-4D0E-A236-B4C5D6E7F8A9}.Debug|x64.ActiveCfg = Debug|Any CPU
{D4E5F6A7-B8C9-4D0E-A236-B4C5D6E7F8A9}.Debug|x64.Build.0 = Debug|Any CPU
{D4E5F6A7-B8C9-4D0E-A236-B4C5D6E7F8A9}.Debug|x86.ActiveCfg = Debug|Any CPU
{D4E5F6A7-B8C9-4D0E-A236-B4C5D6E7F8A9}.Debug|x86.Build.0 = Debug|Any CPU
{D4E5F6A7-B8C9-4D0E-A236-B4C5D6E7F8A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4E5F6A7-B8C9-4D0E-A236-B4C5D6E7F8A9}.Release|Any CPU.Build.0 = Release|Any CPU
{D4E5F6A7-B8C9-4D0E-A236-B4C5D6E7F8A9}.Release|x64.ActiveCfg = Release|Any CPU
{D4E5F6A7-B8C9-4D0E-A236-B4C5D6E7F8A9}.Release|x64.Build.0 = Release|Any CPU
{D4E5F6A7-B8C9-4D0E-A236-B4C5D6E7F8A9}.Release|x86.ActiveCfg = Release|Any CPU
{D4E5F6A7-B8C9-4D0E-A236-B4C5D6E7F8A9}.Release|x86.Build.0 = Release|Any CPU
{BA4579AF-9C20-477A-891B-926968B11C68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA4579AF-9C20-477A-891B-926968B11C68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA4579AF-9C20-477A-891B-926968B11C68}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -863,6 +887,18 @@ Global
{12C4A556-E62E-4EC0-BCD9-E9D4E1F3D430}.Release|x64.Build.0 = Release|Any CPU
{12C4A556-E62E-4EC0-BCD9-E9D4E1F3D430}.Release|x86.ActiveCfg = Release|Any CPU
{12C4A556-E62E-4EC0-BCD9-E9D4E1F3D430}.Release|x86.Build.0 = Release|Any CPU
{396E6929-5365-4116-8AA8-DF5327247798}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{396E6929-5365-4116-8AA8-DF5327247798}.Debug|Any CPU.Build.0 = Debug|Any CPU
{396E6929-5365-4116-8AA8-DF5327247798}.Debug|x64.ActiveCfg = Debug|Any CPU
{396E6929-5365-4116-8AA8-DF5327247798}.Debug|x64.Build.0 = Debug|Any CPU
{396E6929-5365-4116-8AA8-DF5327247798}.Debug|x86.ActiveCfg = Debug|Any CPU
{396E6929-5365-4116-8AA8-DF5327247798}.Debug|x86.Build.0 = Debug|Any CPU
{396E6929-5365-4116-8AA8-DF5327247798}.Release|Any CPU.ActiveCfg = Release|Any CPU
{396E6929-5365-4116-8AA8-DF5327247798}.Release|Any CPU.Build.0 = Release|Any CPU
{396E6929-5365-4116-8AA8-DF5327247798}.Release|x64.ActiveCfg = Release|Any CPU
{396E6929-5365-4116-8AA8-DF5327247798}.Release|x64.Build.0 = Release|Any CPU
{396E6929-5365-4116-8AA8-DF5327247798}.Release|x86.ActiveCfg = Release|Any CPU
{396E6929-5365-4116-8AA8-DF5327247798}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -882,6 +918,7 @@ Global
{D2E8AC42-2751-4AF9-87E4-54A8B2034360} = {6EAC4D2C-4A86-4C9F-8427-CB374F69F08C}
{1A6A0104-F610-4DD3-88BE-C4029034E5DA} = {BF4543A8-0731-4FDD-BB6B-0ADB9561F981}
{34A46D97-5996-46B3-BDCA-631EDAA0E210} = {FA350BD6-C29D-40D9-BA47-FE5FBDFC84A0}
{D4E5F6A7-B8C9-4D0E-A236-B4C5D6E7F8A9} = {FA350BD6-C29D-40D9-BA47-FE5FBDFC84A0}
{BA4579AF-9C20-477A-891B-926968B11C68} = {F6F48227-B3C5-4A51-B33F-FF9AD96352DB}
{6F24BF9C-EA4E-42AB-A9A8-435CE69362B8} = {F6F48227-B3C5-4A51-B33F-FF9AD96352DB}
{64775F93-5A04-495F-97C6-BDB3835B18F6} = {F6F48227-B3C5-4A51-B33F-FF9AD96352DB}
Expand Down Expand Up @@ -926,6 +963,10 @@ Global
{E0B26803-010B-4198-8016-002242076B61} = {583FFBBD-421C-4FB7-BBDA-F9CAF35A354A}
{136F1E35-8B20-465C-8D42-30A5A0D0DA1F} = {583FFBBD-421C-4FB7-BBDA-F9CAF35A354A}
{12C4A556-E62E-4EC0-BCD9-E9D4E1F3D430} = {BF4543A8-0731-4FDD-BB6B-0ADB9561F981}
{396E6929-5365-4116-8AA8-DF5327247798} = {6360202A-F931-4BBD-ADBD-C9A628EE59F8}
{03997797-E7F5-0643-168D-B8EA7178C2FE} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
{EC447DCF-ABFA-6E24-52A5-D7FD48A5C558} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
{CC1F4FA2-92F2-BA4B-815B-7EC2CBBCCF50} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {88B478F4-FD3B-4C24-9E84-4FAAF0254397}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using AutoMapper;
using Grand.Mapping;
using Grand.Business.Core.Dto;
using Grand.Domain.Catalog;
using Grand.Infrastructure.Mapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using AutoMapper;
using Grand.Mapping;
using Grand.Business.Core.Dto;
using Grand.Domain.Catalog;
using Grand.Infrastructure.Mapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using AutoMapper;
using Grand.Mapping;
using Grand.Business.Core.Dto;
using Grand.Domain.Catalog;
using Grand.Infrastructure.Mapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using AutoMapper;
using Grand.Mapping;
using Grand.Business.Core.Dto;
using Grand.Domain.Catalog;
using Grand.Infrastructure.Mapper;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Grand.Infrastructure/Grand.Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<PackageReference Include="Microsoft.Extensions.Caching.Memory" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" />
<PackageReference Include="AutoMapper" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" />
<PackageReference Include="MediatR" />
Expand All @@ -20,5 +19,6 @@
<ItemGroup>
<ProjectReference Include="..\Grand.Data\Grand.Data.csproj" />
<ProjectReference Include="..\Grand.Domain\Grand.Domain.csproj" />
<ProjectReference Include="..\Grand.Mapping\Grand.Mapping.csproj" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Core/Grand.Infrastructure/Mapper/AutoMapperConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using AutoMapper;
using Grand.Mapping;

namespace Grand.Infrastructure.Mapper;

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Grand.Infrastructure/Mapper/MappingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public static class MappingExtensions
{
public static TDestination MapTo<TSource, TDestination>(this TSource source)
public static TDestination MapTo<TSource, TDestination>(this TSource source) where TDestination : new()
{
return AutoMapperConfig.Mapper.Map<TSource, TDestination>(source);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Core/Grand.Infrastructure/StartupBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using AutoMapper;
using Grand.Data;
using Grand.Data;
using Grand.Mapping;
using Grand.Infrastructure.Configuration;
using Grand.Infrastructure.Extensions;
using Grand.Infrastructure.Mapper;
Expand Down Expand Up @@ -67,7 +67,7 @@ private static void InitAutoMapper(ITypeSearcher typeSearcher)
//create AutoMapper configuration
var config = new MapperConfiguration(cfg =>
{
foreach (var instance in instances) cfg.AddProfile(instance.GetType());
foreach (var instance in instances) cfg.AddProfile((Grand.Mapping.Profile)instance);
});

//register automapper
Expand Down
3 changes: 3 additions & 0 deletions src/Core/Grand.Mapping/Grand.Mapping.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\Build\Grand.Common.props" />
</Project>
25 changes: 25 additions & 0 deletions src/Core/Grand.Mapping/GrandMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections.Frozen;

namespace Grand.Mapping;

internal sealed class GrandMapper : IMapper
{
private readonly FrozenDictionary<(Type, Type), Delegate> _mappings;

internal GrandMapper(Dictionary<(Type, Type), Delegate> mappings)
=> _mappings = mappings.ToFrozenDictionary();

public TDest Map<TSource, TDest>(TSource source) where TDest : new()
{
return Map(source, new TDest());
}

public TDest Map<TSource, TDest>(TSource source, TDest destination)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(destination);
if (_mappings.TryGetValue((typeof(TSource), typeof(TDest)), out var del))
((Action<TSource, TDest>)del)(source, destination);
return destination;
}
}
7 changes: 7 additions & 0 deletions src/Core/Grand.Mapping/IMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Grand.Mapping;

public interface IMapper
{
TDest Map<TSource, TDest>(TSource source) where TDest : new();
TDest Map<TSource, TDest>(TSource source, TDest destination);
}
7 changes: 7 additions & 0 deletions src/Core/Grand.Mapping/IMapperConfigurationExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Grand.Mapping;

public interface IMapperConfigurationExpression
{
void AddProfile(Profile profile);
void AddProfile<T>() where T : Profile, new() => AddProfile(new T());
}
14 changes: 14 additions & 0 deletions src/Core/Grand.Mapping/IMappingExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Linq.Expressions;

namespace Grand.Mapping;

public interface IMappingExpression<TSource, TDest>
{
IMappingExpression<TSource, TDest> ForMember<TMember>(
Expression<Func<TDest, TMember>> destMember,
Action<IMemberConfigurationExpression<TSource, TDest, TMember>> opts);

IMappingExpression<TSource, TDest> ForPath<TMember>(
Expression<Func<TDest, TMember>> destPath,
Action<IMemberConfigurationExpression<TSource, TDest, TMember>> opts);
}
10 changes: 10 additions & 0 deletions src/Core/Grand.Mapping/IMemberConfigurationExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Linq.Expressions;

namespace Grand.Mapping;

public interface IMemberConfigurationExpression<TSource, TDest, TMember>

Check warning on line 5 in src/Core/Grand.Mapping/IMemberConfigurationExpression.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'TDest' is not used in the interface.

See more on https://sonarcloud.io/project/issues?id=grandnode_grandnode2&issues=AZ05ldkP17cMkptUjJYt&open=AZ05ldkP17cMkptUjJYt&pullRequest=664

Check warning on line 5 in src/Core/Grand.Mapping/IMemberConfigurationExpression.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Reduce the number of generic parameters in the 'IMemberConfigurationExpression' interface to no more than the 2 authorized.

See more on https://sonarcloud.io/project/issues?id=grandnode_grandnode2&issues=AZ05ldkP17cMkptUjJYv&open=AZ05ldkP17cMkptUjJYv&pullRequest=664

Check warning on line 5 in src/Core/Grand.Mapping/IMemberConfigurationExpression.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'TMember' is not used in the interface.

See more on https://sonarcloud.io/project/issues?id=grandnode_grandnode2&issues=AZ05ldkP17cMkptUjJYu&open=AZ05ldkP17cMkptUjJYu&pullRequest=664
{
void Ignore();
void MapFrom<TResult>(Expression<Func<TSource, TResult>> mapExpression);
void Condition(Expression<Func<TSource, bool>> condition);
}
7 changes: 7 additions & 0 deletions src/Core/Grand.Mapping/Internal/IMappingConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Grand.Mapping.Internal;

internal interface IMappingConfiguration
{
(Type Source, Type Dest) GetTypes();
Delegate CompileDelegate(HashSet<(Type, Type)> registeredTypes, Dictionary<(Type, Type), Delegate> mappings);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Grand.Mapping.Internal;

internal sealed class MapperConfigurationExpressionImpl : IMapperConfigurationExpression
{
private readonly List<IMappingConfiguration> _configurations = new();

public void AddProfile(Profile profile)
=> _configurations.AddRange(profile.GetConfigurations());

internal IEnumerable<IMappingConfiguration> GetConfigurations() => _configurations;
}
Loading
Loading