Add multi-targeting support for .NET frameworks
Introduced conditional compilation using `#if NET` directives to enable support for multiple frameworks (`net462`, `net480`, and `net8.0`). Updated the project file to support multi-targeting and added framework-specific dependencies conditionally. Refactored namespaces, interfaces, classes, validators, and handlers to ensure compatibility with targeted frameworks. Enhanced dependency injection setup and adjusted logic in `GetSenderQueryHandler` for framework-specific behavior. Ensured consistency and maintainability by wrapping framework- specific code blocks with `#if NET` directives.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#if NET
|
||||
using DigitalData.MessagingService.Abstraction;
|
||||
using DigitalData.MessagingService.Application.Common.Models.MailSearch;
|
||||
|
||||
@@ -31,3 +32,4 @@ public interface IImapEmailService
|
||||
string folder = "INBOX",
|
||||
CancellationToken cancellationToken = default);
|
||||
}
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
#if NET
|
||||
using AutoMapper;
|
||||
using DigitalData.MessagingService.Application.EmailSending.Commands;
|
||||
using DigitalData.MessagingService.Abstraction;
|
||||
@@ -18,3 +19,4 @@ public class EmailMappingProfile : Profile
|
||||
.ForMember(dest => dest.Attachments, opt => opt.MapFrom(src => src.Attachments));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
#if NET
|
||||
namespace DigitalData.MessagingService.Application.Common.Models.MailSearch;
|
||||
|
||||
/// <summary>
|
||||
@@ -11,3 +12,4 @@ namespace DigitalData.MessagingService.Application.Common.Models.MailSearch;
|
||||
/// <param name="After">Earliest date to include (inclusive). Maps to IMAP <c>SINCE</c>.</param>
|
||||
/// <param name="Before">Latest date to include (inclusive). Maps to IMAP <c>BEFORE</c> (next day is used internally).</param>
|
||||
public record DateFilter(DateTime? After = null, DateTime? Before = null);
|
||||
#endif
|
||||
@@ -1,4 +1,5 @@
|
||||
namespace DigitalData.MessagingService.Application.Common.Models.MailSearch;
|
||||
#if NET
|
||||
namespace DigitalData.MessagingService.Application.Common.Models.MailSearch;
|
||||
|
||||
/// <summary>
|
||||
/// Describes all criteria and options used when searching an IMAP mailbox.
|
||||
@@ -76,3 +77,4 @@ public record MailSearchFilter
|
||||
/// </summary>
|
||||
public DateFilter? Date { get; init; } = null;
|
||||
}
|
||||
#endif
|
||||
@@ -1,4 +1,5 @@
|
||||
namespace DigitalData.MessagingService.Application.Common.Models.MailSearch;
|
||||
#if NET
|
||||
namespace DigitalData.MessagingService.Application.Common.Models.MailSearch;
|
||||
|
||||
/// <summary>
|
||||
/// Constrains the search to a specific UID or a UID range.
|
||||
@@ -12,3 +13,4 @@
|
||||
/// <param name="Max">Upper bound of the UID range (inclusive). Ignored when <see cref="Absolute"/> is set.</param>
|
||||
/// <param name="Absolute">Exact UID to match. When set, <see cref="Min"/> and <see cref="Max"/> must be <see langword="null"/>.</param>
|
||||
public record UidFilter(long? Min = null, long? Max = null, long? Absolute = null);
|
||||
#endif
|
||||
@@ -1,4 +1,5 @@
|
||||
using DigitalData.MessagingService.Abstraction;
|
||||
#if NET
|
||||
using DigitalData.MessagingService.Abstraction;
|
||||
|
||||
namespace DigitalData.MessagingService.Application.Common.Options;
|
||||
|
||||
@@ -21,3 +22,4 @@ public class EmailAccountsOptions
|
||||
/// </summary>
|
||||
public int SyncIntervalSeconds { get; init; } = 300;
|
||||
}
|
||||
#endif
|
||||
@@ -1,8 +1,8 @@
|
||||
#if NET
|
||||
using DigitalData.MessagingService.Application.Common.Options;
|
||||
using FluentValidation;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Reflection;
|
||||
|
||||
namespace DigitalData.MessagingService.Application;
|
||||
@@ -43,3 +43,4 @@ public static class DependencyInjection
|
||||
return services;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,9 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<TargetFrameworks>net462;net480;net8.0</TargetFrameworks>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -11,7 +12,7 @@
|
||||
<ProjectReference Include="..\DigitalData.MessagingService.Abstraction\DigitalData.MessagingService.Abstraction.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
|
||||
<PackageReference Include="AutoMapper" Version="16.2.0" />
|
||||
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="12.1.1" />
|
||||
<PackageReference Include="MediatR" Version="14.2.0" />
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using DigitalData.MessagingService.Application.Common.Options;
|
||||
#if NET
|
||||
using DigitalData.MessagingService.Application.Common.Options;
|
||||
using DigitalData.MessagingService.Abstraction;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -37,3 +38,4 @@ public class GetSenderQueryHandler(IOptions<EmailAccountsOptions> Options, ILogg
|
||||
return Task.FromResult(accounts.FirstOrDefault());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
#if NET
|
||||
using DigitalData.MessagingService.Application.EmailAccount.Queries;
|
||||
using FluentValidation;
|
||||
|
||||
@@ -25,3 +26,4 @@ public class GetSenderQueryValidator : AbstractValidator<GetSenderQuery>
|
||||
});
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
#if NET
|
||||
using DigitalData.MessagingService.Application.Common.Interfaces;
|
||||
using DigitalData.MessagingService.Application.EmailAccount.Queries;
|
||||
using DigitalData.MessagingService.Domain.Exceptions;
|
||||
@@ -40,3 +41,4 @@ public class MarkEmailAsSeenCommandHandler(
|
||||
await ImapService.MarkAsSeenAsync(account, request.Uid, request.Folder, cancellationToken);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
#if NET
|
||||
using DigitalData.MessagingService.Abstraction;
|
||||
using DigitalData.MessagingService.Application.Common.Interfaces;
|
||||
using DigitalData.MessagingService.Application.Common.Models.MailSearch;
|
||||
@@ -43,3 +44,4 @@ public class FetchEmailsQueryHandler(
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,4 +1,5 @@
|
||||
using DigitalData.MessagingService.Application.Common.Models.MailSearch;
|
||||
#if NET
|
||||
using DigitalData.MessagingService.Application.Common.Models.MailSearch;
|
||||
using FluentValidation;
|
||||
|
||||
namespace DigitalData.MessagingService.Application.EmailReceiving.Validators;
|
||||
@@ -35,3 +36,4 @@ public class DateFilterValidator : AbstractValidator<DateFilter>
|
||||
.When(x => x.After is not null && x.Before is not null);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
#if NET
|
||||
using DigitalData.MessagingService.Application.EmailReceiving.Queries;
|
||||
using FluentValidation;
|
||||
|
||||
@@ -20,3 +21,4 @@ public class FetchEmailsQueryValidator : AbstractValidator<FetchEmailsQuery>
|
||||
.SetValidator(new MailSearchFilterValidator());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
#if NET
|
||||
using DigitalData.MessagingService.Application.Common.Models.MailSearch;
|
||||
using FluentValidation;
|
||||
|
||||
@@ -49,3 +50,4 @@ public class MailSearchFilterValidator : AbstractValidator<MailSearchFilter>
|
||||
.When(x => x.Date is not null);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,4 +1,5 @@
|
||||
using DigitalData.MessagingService.Application.Common.Models.MailSearch;
|
||||
#if NET
|
||||
using DigitalData.MessagingService.Application.Common.Models.MailSearch;
|
||||
using FluentValidation;
|
||||
|
||||
namespace DigitalData.MessagingService.Application.EmailReceiving.Validators;
|
||||
@@ -46,3 +47,4 @@ public class UidFilterValidator : AbstractValidator<UidFilter>
|
||||
.When(x => x.Min is not null && x.Max is not null);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
#if NET
|
||||
using AutoMapper;
|
||||
using DigitalData.MessagingService.Application.EmailAccount.Queries;
|
||||
using DigitalData.MessagingService.Domain.Exceptions;
|
||||
@@ -70,3 +71,4 @@ public class PublishEmailCommandHandler(ISender Sender, ISendingEmailPublisher P
|
||||
return sendingEmailEvent.Id;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
#if NET
|
||||
using DigitalData.MessagingService.Application.EmailSending.Commands;
|
||||
using FluentValidation;
|
||||
|
||||
@@ -32,3 +33,4 @@ public class PublishEmailCommandValidator : AbstractValidator<PublishEmailComman
|
||||
.WithMessage("Body is required");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user