refactor: refinamentos
This commit is contained in:
@@ -10,7 +10,8 @@ internal class CustomerConfiguration : IEntityTypeConfiguration<Customer>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Customer> builder)
|
||||
{
|
||||
builder.ConfigureBaseEntity();
|
||||
builder
|
||||
.ConfigureBaseEntity();
|
||||
|
||||
builder
|
||||
.Property(customer => customer.FirstName)
|
||||
@@ -36,7 +37,7 @@ internal class CustomerConfiguration : IEntityTypeConfiguration<Customer>
|
||||
.IsRequired() // NOT NULL
|
||||
.HasMaxLength(254)
|
||||
.HasColumnName(nameof(Customer.Email))
|
||||
.IsEncrypted();
|
||||
.IsEncrypted(); // Encryption
|
||||
|
||||
// Unique Index
|
||||
ownedNav
|
||||
|
||||
@@ -22,7 +22,6 @@ public sealed class NoSqlDbContext : IReadDbContext, ISynchronizeDb
|
||||
|
||||
private const string DatabaseName = "Shop";
|
||||
private const int RetryCount = 2;
|
||||
private static readonly Random Rnd = new();
|
||||
|
||||
private static readonly ReplaceOptions DefaultReplaceOptions = new()
|
||||
{
|
||||
@@ -136,9 +135,10 @@ public sealed class NoSqlDbContext : IReadDbContext, ISynchronizeDb
|
||||
// but then at progressively longer intervals: for example, after 2, 4, 8, 15, then 30 seconds.
|
||||
// REF: https://github.com/App-vNext/Polly/wiki/Retry-with-jitter#simple-jitter
|
||||
var sleepDuration =
|
||||
TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)) + TimeSpan.FromMilliseconds(Rnd.Next(0, 1000));
|
||||
TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)) + TimeSpan.FromMilliseconds(Random.Shared.Next(0, 1000));
|
||||
|
||||
logger.LogWarning("----- MongoDB: Retry #{Count} with delay {Delay}", retryAttempt, sleepDuration);
|
||||
|
||||
return sleepDuration;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ using Shop.Query.QueriesModel;
|
||||
|
||||
namespace Shop.Query.Data.Repositories;
|
||||
|
||||
internal class CustomerReadOnlyRepository(IReadDbContext readDbContext) : BaseReadOnlyRepository<CustomerQueryModel, Guid>(readDbContext), ICustomerReadOnlyRepository
|
||||
internal class CustomerReadOnlyRepository(IReadDbContext readDbContext)
|
||||
: BaseReadOnlyRepository<CustomerQueryModel, Guid>(readDbContext), ICustomerReadOnlyRepository
|
||||
{
|
||||
public async Task<IEnumerable<CustomerQueryModel>> GetAllAsync() =>
|
||||
await Collection
|
||||
|
||||
@@ -32,5 +32,14 @@ public class CustomerQueryModel : IQueryModel<Guid>
|
||||
public string Email { get; private init; }
|
||||
public DateTime DateOfBirth { get; private init; }
|
||||
|
||||
public string FullName => (FirstName + " " + LastName).Trim();
|
||||
public string FullName
|
||||
{
|
||||
get
|
||||
{
|
||||
var fullNameSpan = new Span<char>(new char[FirstName.Length + LastName.Length + 1]);
|
||||
FirstName.AsSpan().CopyTo(fullNameSpan);
|
||||
LastName.AsSpan().CopyTo(fullNameSpan[FirstName.Length..]);
|
||||
return fullNameSpan.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user