I declare that I look into the domain event template and read a lot of resources on this subject, but I cannot find a good implementation method for our requirements. We basically have a Service / Domain layer that wraps a read / write repository layer with a simplified CQRS implementation. We have an ASP.NET Mvc application that consumes this level of service / domain. The entire application is associated with Autofac, and I would like this to happen:
When a news item is created by calling "CreateNews" in the register of the service layer, that event should be raised like this:
public void CreateNews(Domain.Entities.News.NewsBO news) { ValidateBusinessObject(news); var entityNews = AutoMapper.Mapper.Map<Repositories.Entities.News.News>(news); NewsCommandRepository.Create(entityNews); _domainEventManager.Register<NewsCreatedDomainEvent>(x => x.News = news); }
This happens in a transaction, and I donβt really want to raise the event until the save is completed, so in our method of saving changes I want to do this:
public void SaveChanges() { _repoCommandManager.SaveChanges(); _domainEventManager.RaiseEvents(); }
Then in our ASP.NET Mvc application, I want to have an IHandler implementation that looks like this:
public class NewsCreatedDomainEventCacheHandler : IHandles<Project.Services.Domain.Events.News.NewsCreatedDomainEvent> { public void Handle(Services.Domain.Events.News.NewsCreatedDomainEvent @event) {
I cannot figure out how to promote this event from the save method and invoke the implementation in a Web.Mvc application.
Any suggestions would be appreciated.
source share