مدیریت مباحث همزمانی مرتبط با یک Rich Domain Model با استفاده از EFCore و الگوی Aggregate
301, MovedPermanently
https://www.kamilgrzybek.com/design/handling-concurrency-aggregate-pattern-and-ef-core/ icon

In summary, the most important issues here are:

  • The Aggregate’s main task is to protect invariants (business rules, the boundary of immediate consistency)
  • In a multi-threaded environment, when multiple threads are running simultaneously on the same Aggregate, a business rule may be broken
  • A way to solve concurrency conflicts is to use Pessimistic or Optimistic concurrency techniques
  • Pessimistic Concurrency involves the use of a database transaction and a locking mechanism. In this way, requests are processed one after the other, so basically concurrency is lost and it can lead to deadlocks.
  • Optimistic Concurrency technique is based on versioning database records and checking whether the previously loaded version has not been changed by another thread.
  • Entity Framework Core supports Optimistic Concurrency. Pessimistic Concurrency is not supported
  • The Aggregate must always be treated and versioned as a single unit
  • Domain events are an indicator, that state was changed so Aggregate version should be changed as well 
public class AggregateRootBase : Entity, IAggregateRoot
{
    private int _versionId;

    public void IncreaseVersion()
    {
        _versionId++;
    }
}
internal sealed class OrderEntityTypeConfiguration : IEntityTypeConfiguration<Order>
{
    public void Configure(EntityTypeBuilder<Order> builder)
    {
        builder.Property("_versionId").HasColumnName("VersionId").IsConcurrencyToken();
 
        //...
    }
}
var order = await _ordersContext.Orders.FindAsync(orderId);
order.AddOrderLine(request.ProductCode); 
var domainEvents = DomainEventsHelper.GetAllDomainEvents(order);
if (domainEvents.Any())
{
    order.IncreaseVersion();
}
await _ordersContext.SaveChangesAsync();


مدیریت مباحث همزمانی مرتبط با یک Rich Domain Model با استفاده از EFCore و الگوی Aggregate
مدیریت یکپارچگی داده ها در معماری میکروسرویس با الگوی saga
200, OK
https://chrisrichardson.net/post/microservices/2019/07/09/developing-sagas-part-1.html icon

در معماری میکروسرویس، هر سرویس دیتابیس مربوط به خود را دارد. بنابراین برای انجام یک تراکنش احتیاج به یک تراکنش توزیع شده میان سرویس‌ها هست، که یکپارچگی داده‌ها را با چندین تراکنش محلی تضمین کند. الگوی saga برای پیاده سازی این تراکنش توزیع شده ارائه شده است.

  • choreography-based saga
  • orchestration-based saga
مدیریت یکپارچگی داده ها در معماری میکروسرویس با الگوی saga
از پیاده سازی Repository Pattern با یک ORM پرهیز کنید!
200, OK
https://codeopinion.com/avoiding-the-repository-pattern-with-an-orm/ icon

For many years now I’ve advocated not using the repository pattern on top of an ORM such as Entity Framework. There are many reasons why that I’ll try and cover throughout this post based on ways that I’ve seen it implemented. Meaning, this post is talking about poorly implemented approaches or pitfalls that I’ve seen. 

از پیاده سازی Repository Pattern با یک ORM پرهیز کنید!
IQueryable و طراحی‌های نشتی‌دار
200, OK
https://blog.ploeh.dk/2012/03/26/IQueryableTisTightCoupling/ icon
public interface IRepository
{
    IQueryable<T> Query<T>();
}
Programmers who define such interfaces invariably have a specific ORM in mind, and they implicitly tend to stay within the bounds they know are safe for that specific ORM. This is a leaky abstraction .  
IQueryable و طراحی‌های نشتی‌دار