Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Object Mappings APIs #14932

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/OrchardCore.Build/Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<PackageManagement Include="OpenIddict.Validation.SystemNetHttp" Version="5.6.0" />
<PackageManagement Include="OrchardCore.Translations.All" Version="1.8.0" />
<PackageManagement Include="PdfPig" Version="0.1.8" />
<PackageManagement Include="Riok.Mapperly" Version="3.4.0" />
<PackageManagement Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageManagement Include="Shortcodes" Version="1.3.3" />
<PackageManagement Include="SixLabors.ImageSharp.Web" Version="3.1.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
<ProjectReference Include="..\..\OrchardCore\OrchardCore.DisplayManagement\OrchardCore.DisplayManagement.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Email.Abstractions\OrchardCore.Email.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Email.Core\OrchardCore.Email.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Infrastructure\OrchardCore.Infrastructure.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Navigation.Core\OrchardCore.Navigation.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Module.Targets\OrchardCore.Module.Targets.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ResourceManagement\OrchardCore.ResourceManagement.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="MailKit" />
<PackageReference Include="Riok.Mapperly" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.DataProtection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using OrchardCore.Mappings;
using OrchardCore.Settings;

namespace OrchardCore.Email.Smtp.Services;
Expand Down Expand Up @@ -29,20 +30,7 @@ public void Configure(SmtpOptions options)
.GetAwaiter().GetResult()
.As<SmtpSettings>();

options.DefaultSender = settings.DefaultSender;
options.DeliveryMethod = settings.DeliveryMethod;
options.PickupDirectoryLocation = settings.PickupDirectoryLocation;
options.Host = settings.Host;
options.Port = settings.Port;
options.ProxyHost = settings.ProxyHost;
options.ProxyPort = settings.ProxyPort;
options.EncryptionMethod = settings.EncryptionMethod;
options.AutoSelectEncryption = settings.AutoSelectEncryption;
options.RequireCredentials = settings.RequireCredentials;
options.UseDefaultCredentials = settings.UseDefaultCredentials;
options.UserName = settings.UserName;
options.Password = settings.Password;
options.IgnoreInvalidSslCertificate = settings.IgnoreInvalidSslCertificate;
options = SmtpSettingsMapper.Map(settings);

if (!string.IsNullOrWhiteSpace(settings.Password))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Riok.Mapperly.Abstractions;

namespace OrchardCore.Email.Smtp.Services;

[Mapper]
public static partial class SmtpSettingsMapper
{
public static partial SmtpOptions Map(SmtpSettings source);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace OrchardCore.Mappings;

/// <summary>
/// Represents a contract for mapping objects.
/// </summary>
public interface IMapper
{
/// <summary>
/// Maps the specified source object to a new object of the specified destination type.
/// </summary>
/// <typeparam name="TDestination">The type of object to map to.</typeparam>
/// <param name="source">The object to be mapped.</param>
TDestination Map<TDestination>(object source);

/// <summary>
/// Maps the specified source object to the specified destination object.
/// </summary>
/// <typeparam name="TSource"></typeparam>
/// <typeparam name="TDestination"></typeparam>
/// <param name="source">The object to be mapped.</param>
/// <param name="destination">The object to map to.</param>
/// <returns></returns>
TDestination Map<TSource, TDestination>(TSource source, TDestination destination);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Riok.Mapperly.Abstractions;

namespace OrchardCore.Mappings;

/// <summary>
/// Represents a service for mapping objects.
/// </summary>
[Mapper]
public static partial class ObjectMapper
{
public static partial TTarget Map<TSource, TTarget>(TSource source);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<ItemGroup>
<PackageReference Include="HtmlSanitizer" />
<PackageReference Include="MimeKit" />
<PackageReference Include="Riok.Mapperly" />
</ItemGroup>

<ItemGroup>
Expand Down