title: Domain Events Using DDD/Repo/UoW/Serv
body: <p>I'm making a Rest Service for work, using:</p>
  
  <ul>
  <li>EntityFramework Core.</li>
  <li>Repository pattern</li>
  <li>UnitOfWork.</li>
  <li>Service pattern.</li>
  <li>Data Transfer Objects(Dto).</li>
  <li>Data Access Objects(Entity/Dao)</li>
  </ul>
  
  <p><strong><em>Short about the project:</em></strong></p>
  
  <ul>
  <li><p>Large enterprice Rest API Service.</p></li>
  <li><p>Repositories's are responsible for CRUD and only CRUD.</p></li>
  <li><p>UnitOfWork contains every repository and get's the DbContext through dependency injection.</p></li>
  <li><p>My Dtos's are anemic models, i know this is considered bad practise by a number of people, but when making a Master API with a thousand entities each containing hundreds of columns, this is actually necessary. 
  So my Dto's actually just mirrors the Dao's(Not sensitive information though). </p></li>
  <li><p>Each entity has it's own repository.</p></li>
  <li><p>Each entity has it's own service class, which mainly uses the given entitiy's repository.</p></li>
  <li><p>Each entity has it's own controller and service class, each controller talks to the given service class.  </p></li>
  <li><p>The service class only accepts Dto, each function converts from Dto to Dao, and then validates the entity, throwing an exception if the entity is not valid. When calling the approriate repository function and using UnitOfWork commit function to save the changes.</p></li>
  <li><p>Insert, Update And Delete by Navigation Properties is disabled/not allowed.</p></li>
  <li><p>This Database is in the Cloud and the company i'm working for has only been using edge databases, so we created a "SyncEngine" to synchronize data from the old database to the new cloud-based(this).</p></li>
  </ul>
  
  <p><strong>Here comes the catch, where and how should i implement the events?</strong> </p>
  
  <p>Let's say i have a "User" entity which has a hundred fields required, and i have a factory method inside the entity, which takes hundred parameters length, this is not optimal at all, and then the event would have been triggered before even knowing it was added to the database? So i end up sending an email to the user, but the database is unavailable, so the user is not created, at all.</p>
  
  <p>I know in DDD you should setup and aggregate and have the events inside the Entity etc, but then the events get triggered even if the write to DB was unsuccessful... and let's say i have a model with hundred required fields, it's not appropriate to have a factory method in the Dao/Entity class, which takes a hundred parameters?</p>
  
  <p>Thanks in advance.
  - Sincerely frustrated man</p>