<commit_before>﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using MassTransit;
using MassTransit.SubscriptionConfigurators;
using Nybus.Container;
using Nybus.Utils;

namespace Nybus.Configuration
{
    public class MassTransitRabbitMqBusConfiguration : IBusConfiguration
    {
        public MassTransitRabbitMqBusConfiguration()
        {
            _eventSubscriptions = new List<Action<SubscriptionBusServiceConfigurator>>();
            _commandSubscriptions = new List<Action<SubscriptionBusServiceConfigurator>>();
            _sharedQueueName = Assembly.GetEntryAssembly().FullName.Hash();
        }

        public void SetSharedQueueName(string queueName)
        {
            _sharedQueueName = queueName;
        }

        private string _sharedQueueName;

        public string SharedQueueName
        {
            get { return _sharedQueueName; }
        }

        private IContainer _container;

        public IContainer Container
        {
            get { return _container; }
        }

        public void SetContainer(IContainer container)
        {
            _container = container;
        }

        private readonly List<Action<SubscriptionBusServiceConfigurator>> _eventSubscriptions;

        internal IReadOnlyList<Action<SubscriptionBusServiceConfigurator>> EventSubscriptions
        {
            get { return _eventSubscriptions; }
        }

        private readonly List<Action<SubscriptionBusServiceConfigurator>> _commandSubscriptions;

        internal IReadOnlyList<Action<SubscriptionBusServiceConfigurator>> CommandSubscriptions
        {
            get { return _commandSubscriptions; }
        }

        public void SubscribeToEvent<TEvent>() where TEvent : class, IEvent
        {
            if (_container == null)
            {
                throw new InvalidOperationException("Set the container before you subscribe to events");
            }

            _eventSubscriptions.Add(configurator => configurator.Handler<TEvent>((ctx, e) =>
            {
                IEventHandler<TEvent> handler = _container.Resolve<IEventHandler<TEvent>>();

                Task.WaitAll(HandleEvent(handler, e, ctx));

                _container.Release(handler);
            }));
        }

        public void SubscribeToEvent<TEvent, TEventHandler>() where TEvent : class, IEvent where TEventHandler : IEventHandler<TEvent>
        {
            if (_container == null)
            {
                throw new InvalidOperationException("Set the container before you subscribe to events");
            }

            _eventSubscriptions.Add(configurator => configurator.Handler<TEvent>((ctx, e) =>
            {
                IEventHandler<TEvent> handler = _container.Resolve<TEventHandler>();

                Task.WaitAll(HandleEvent(handler, e, ctx));<commit_msg>Replaced read only properties with expression body (c# 6 feature)<commit_after>﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using MassTransit;
using MassTransit.SubscriptionConfigurators;
using Nybus.Container;
using Nybus.Utils;

namespace Nybus.Configuration
{
    public class MassTransitRabbitMqBusConfiguration : IBusConfiguration
    {
        public MassTransitRabbitMqBusConfiguration()
        {
            _eventSubscriptions = new List<Action<SubscriptionBusServiceConfigurator>>();
            _commandSubscriptions = new List<Action<SubscriptionBusServiceConfigurator>>();
            _sharedQueueName = Assembly.GetEntryAssembly().FullName.Hash();
        }

        public void SetSharedQueueName(string queueName)
        {
            _sharedQueueName = queueName;
        }

        private string _sharedQueueName;

        public string SharedQueueName => _sharedQueueName;

        private IContainer _container;

        public IContainer Container => _container;

        public void SetContainer(IContainer container)
        {
            _container = container;
        }

        private readonly List<Action<SubscriptionBusServiceConfigurator>> _eventSubscriptions;

        internal IReadOnlyList<Action<SubscriptionBusServiceConfigurator>> EventSubscriptions => _eventSubscriptions;

        private readonly List<Action<SubscriptionBusServiceConfigurator>> _commandSubscriptions;

        internal IReadOnlyList<Action<SubscriptionBusServiceConfigurator>> CommandSubscriptions => _commandSubscriptions;

        public void SubscribeToEvent<TEvent>() where TEvent : class, IEvent
        {
            if (_container == null)
            {
                throw new InvalidOperationException("Set the container before you subscribe to events");
            }

            _eventSubscriptions.Add(configurator => configurator.Handler<TEvent>((ctx, e) =>
            {
                IEventHandler<TEvent> handler = _container.Resolve<IEventHandler<TEvent>>();

                Task.WaitAll(HandleEvent(handler, e, ctx));

                _container.Release(handler);
            }));
        }

        public void SubscribeToEvent<TEvent, TEventHandler>() where TEvent : class, IEvent where TEventHandler : IEventHandler<TEvent>
        {
            if (_container == null)
            {
                throw new InvalidOperationException("Set the container before you subscribe to events");
            }

            _eventSubscriptions.Add(configurator => configurator.Handler<TEvent>((ctx, e) =>
            {
                IEventHandler<TEvent> handler = _container.Resolve<TEventHandler>();

                Task.WaitAll(HandleEvent(handler, e, ctx));
{'fraction_non_alphanumeric': 0.07655417406749555, 'fraction_numerical': 0.00017761989342806393, 'mean_word_length': 2.642302716688228, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6721228', 'n_tokens_mistral': 1366, 'n_tokens_neox': 1346, 'n_words': 290}