'Why the method uses Activator.CreateInstance instead of directly "new Class()"?
In the method GetNotificationCorrespondingToDomainEvent in
https://github.com/jasontaylordev/CleanArchitecture/blob/main/src/Infrastructure/Services/DomainEventService.cs, it has the following method,
private INotification GetNotificationCorrespondingToDomainEvent(DomainEvent domainEvent)
{
return (INotification)Activator.CreateInstance(
typeof(DomainEventNotification<>).MakeGenericType(domainEvent.GetType()), domainEvent)!;
}
How it compares with new DomainEventNotification(....)? BTW, is the ! at the end necessary?
private INotification GetNotificationCorrespondingToDomainEvent(DomainEvent domainEvent)
{
return new DomainEventNotification<DomainEvent>(domainEvent)!;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
