Skip to content

Instantly share code, notes, and snippets.

@mattbrailsford
Created September 29, 2020 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattbrailsford/a7da66f0c092a49c097cbf56e1ba9649 to your computer and use it in GitHub Desktop.
Save mattbrailsford/a7da66f0c092a49c097cbf56e1ba9649 to your computer and use it in GitHub Desktop.
public class MyEntityNotificationBase : NotificationEventBase
{
public MyEntity Entity { get; }
public MyEntityNotificationBase(MyEntity entity)
{
Entity = entity;
}
}
public class MyEntityAddingNotification : MyEntityNotificationBase
{
public MyEntityAddingNotification(MyEntity entity)
: base(entity)
{ }
}
public class MyEntityAddedNotification : MyEntityNotificationBase
{
public MyEntityAddedNotification(MyEntity entity)
: base(entity)
{ }
}
public class MyService
{
...
public void AddEntity(MyEntity entity)
{
using (var uow = _uowProvider.Create())
using (var repo = _repositoryFactory.CreateMyEntityRepository(uow))
{
var now = DateTime.UtcNow;
entity.CreateDate = now;
entity.UpdateDate = now;
EventBus.Dispatch(new MyEntityAddingNotification(entity));
repo.Insert(entity);
uow.ScheduleNotification(new MyEntityAddedNotification(entity));
uow.Complete();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment