using CloudBuilder.Core.DatabaseAccessor.Entity;
using CloudBuilder.Core.DependencyInjection.EventBuses;
using CloudBuilder.Security.Publisher;
using CloudBuilder.Security.Subscriber;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CloudBuilder.Security.Service.Publisher
{
    public class SecurityUserRegisterPublisher : ISecurityUserRegisterPublisher
    {
        private readonly IApplicationService service;

        public SecurityUserRegisterPublisher(IApplicationService service)
        {
            this.service = service;
        }

        public void Publish(EventData eventData)
        {
            IEnumerable<ISecurityUserRegisterSubscriber> subscribers = service.ServiceProvider.GetServices<ISecurityUserRegisterSubscriber>();

            foreach (var subscriber in subscribers)
            {
                subscriber.Handle(eventData);
            }
        }
    }
}
