0

I am in process of app refactoring. Simple CRUD logic before was covered with Generic Repo & Unit Of Work pattern before. Right now the app receives more requirements and they are gonna be changing, thus to make the app be able to expanded I'm trying to use Event Driven architecture in BL. Here are the questions I'm struggling with:

  1. how to share the db context? passing it through the args feels like bad idea, but injecting them through the interface will not be able to guarantee that there's only one context.
  2. Should all the secondary operations covered in one transaction?
  3. What is the proper way to handle errors here? For example, UpdateException.
// for example, recalculating inventory after creating order or logging changes after order transaction
public class SomethingHappenedEvent : IDomainEvent{}

public class SomethingHappenedEventHandler : IDomainHandler<SomethingHappenedEvent>
{
    public void Handle(SomethingHappenedEvent args)
    {

        // run db stuff with Entity Framework
    }
}

Client class:

public class SomeBussinessLogic
{
     public void ProccessSomeLogic()
     {
          // main responsibility of method
          DomainEvent.Raise(new SomethingHappenedEvent();
     }
}
col403
  • 41
  • 5
  • Each question you raise is a broad topic on its own, it would, therefore, be hard to give you a satisfying answer to a question, let alone all three. Because of this, your question is unsuited for Stack Overflow. Stack Overflow questions should typically be very concrete, describing one single, specific problem that can be demonstrated with a limited amount of code. – Steven Jul 24 '20 at 14:42
  • But perhaps the following Stack Overflow questions might get you started: [10585478](https://stackoverflow.com/questions/10585478/), [9892137](https://stackoverflow.com/questions/9892137/). – Steven Jul 24 '20 at 14:47
  • @Steven, thanks for the following Stack Overflow questions you provided - they seem good to start with. – col403 Jul 27 '20 at 12:04

0 Answers0