is there any way to handle events from mediator inside the ViewModel. If VM implemetns interface INotification it must be singleton or creates/destroy based on mediators rules.
Or how to solve this issue. For example: when i create new Customer(), domain model generates event CustomerCreatedEvent() and i want to update counter on my mobile app UI.
I know there are events in c#, where can i subscribe/unsubscribe VM but it is "diffrend kind" of event.
Thanks for advice.
Update 01 I found a solution when VM and Notification are independet units.
public class CustomerCreatedHandler : INotification<CustomerCreatedEvent>
{
private readonly CustomerPageViewModel _viewModel;
public CustomerCreatedHandler(CustomerPageViewModel viewModel)
{
_viewModel = viewModel;
}
public Task Handle(CustomerCreatedEvent customerCreatedEvent)
{
// set property of VM
_viewModel.Count = customerCreatedEvent.Count;
return Task.CompletedTask;
}
}
It should be working. VM is singleton and Notification handler can be destroyed after work is finished.