refactor: Aktualisierung der Anwendungs- und Infrastrukturebenen, so dass die Infrastruktur von der Anwendung abhängig ist.
- Repository-Schnittstellen wurden in die Anwendungsschicht verschoben. - Erweiterungsmethoden für die Injektion von Repository-Abhängigkeiten wurden in die Infrastruktur verschoben.
This commit is contained in:
@@ -1,34 +1,33 @@
|
||||
using DigitalData.Core.Infrastructure;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using EnvelopeGenerator.Infrastructure.Contracts;
|
||||
using EnvelopeGenerator.Application.Contracts.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using static EnvelopeGenerator.Common.Constants;
|
||||
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories
|
||||
{
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories;
|
||||
|
||||
public class EmailTemplateRepository : CRUDRepository<EmailTemplate, int, EGDbContext>, IEmailTemplateRepository
|
||||
{
|
||||
private readonly IMemoryCache _cache;
|
||||
|
||||
public EmailTemplateRepository(EGDbContext dbContext, IMemoryCache cache) : base(dbContext, dbContext.EmailTemplate)
|
||||
public EmailTemplateRepository(EGDbContext dbContext, IMemoryCache cache) : base(dbContext, dbContext.EmailTemplate)
|
||||
{
|
||||
_cache = cache;
|
||||
}
|
||||
|
||||
private readonly Guid key_guid = Guid.NewGuid();
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves an email template based on its name.
|
||||
/// Utilizes in-memory caching to improve performance for the limited number of email templates available.
|
||||
/// If the template is not found in the cache, it queries the database and stores the result in the cache.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of the email template, which corresponds to its name.</param>
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous operation. The task result contains the email template
|
||||
/// if found, otherwise null.
|
||||
/// </returns>
|
||||
public async Task<EmailTemplate?> ReadByNameAsync(EmailTemplateType type) => await _cache.GetOrCreateAsync($"{type}{key_guid}", async _
|
||||
/// <summary>
|
||||
/// Retrieves an email template based on its name.
|
||||
/// Utilizes in-memory caching to improve performance for the limited number of email templates available.
|
||||
/// If the template is not found in the cache, it queries the database and stores the result in the cache.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of the email template, which corresponds to its name.</param>
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous operation. The task result contains the email template
|
||||
/// if found, otherwise null.
|
||||
/// </returns>
|
||||
public async Task<EmailTemplate?> ReadByNameAsync(EmailTemplateType type) => await _cache.GetOrCreateAsync($"{type}{key_guid}", async _
|
||||
=> await _dbSet.Where(t => t.Name == type.ToString()).FirstOrDefaultAsync());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user