You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
899 B
34 lines
899 B
using Infrastructure.Extensions;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace Infrastructure.Domain
|
|
{
|
|
public class EventPublisher : IEventPublisher
|
|
{
|
|
private readonly IServiceProvider _applicationServices;
|
|
|
|
public EventPublisher(IServiceProvider applicationServices)
|
|
{
|
|
this._applicationServices = applicationServices;
|
|
}
|
|
|
|
public virtual void Publish<T>(T eventMessage)
|
|
{
|
|
var subscribers = _applicationServices.GetServices<IEvent<T>>().ToList();
|
|
subscribers.ForEach(subscriber =>
|
|
{
|
|
try
|
|
{
|
|
subscriber.Handle(eventMessage);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.PrintStack();
|
|
}
|
|
}
|
|
);
|
|
}
|
|
}
|
|
} |