Created
September 29, 2020 09:22
-
-
Save mattbrailsford/a7da66f0c092a49c097cbf56e1ba9649 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
{ } | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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