<commit_before>﻿using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Framework.DependencyInjection;
using RabbitMQ.Client;
using RawRabbit.Configuration;
using RawRabbit.Consumer;
using RawRabbit.Consumer.Contract;
using RawRabbit.Consumer.Eventing;
using RawRabbit.Context;
using RawRabbit.Context.Provider;
using RawRabbit.Operations;
using RawRabbit.Operations.Contracts;
using RawRabbit.Serialization;

namespace RawRabbit.Common
{
	public class BusClientFactory
	{
		public static BusClient CreateDefault(RawRabbitConfiguration config = null, Action<IServiceCollection> configureIoc = null)
		{
			var services = new ServiceCollection();
			services
				.AddSingleton<RawRabbitConfiguration>(provider => config ?? new RawRabbitConfiguration())
				.AddSingleton<IConnectionFactory, ConnectionFactory>(p =>
				{
					var cfg = p.GetService<RawRabbitConfiguration>();
					return new ConnectionFactory
					{
						HostName = cfg.Hostname,
						Password = <PASSWORD>,
						UserName = cfg.Username,
						AutomaticRecoveryEnabled = true,
						TopologyRecoveryEnabled = true,
					};
				})
				.AddTransient<IMessageSerializer, JsonMessageSerializer>()
				.AddTransient<IConsumerFactory, EventingBasicConsumerFactory>()
				.AddSingleton<IMessageContextProvider<MessageContext>, DefaultMessageContextProvider>(
					p => new DefaultMessageContextProvider(() => Task.FromResult(Guid.NewGuid())))
				.AddSingleton<IChannelFactory, ChannelFactory>() //TODO: Should this be one/application?
				.AddTransient<IConfigurationEvaluator, ConfigurationEvaluator>()
				.AddTransient<INamingConvetions, NamingConvetions>()
				.AddTransient<ISubscriber<MessageContext>, Subscriber<MessageContext>>()
				.AddTransient<IPublisher, Publisher<MessageContext>>()
				.AddTransient<IResponder<MessageContext>, Responder<MessageContext>>()
				.AddTransient<IRequester, Requester<MessageContext>>(
					p => new Requester<MessageContext>(
						p.GetService<IChannelFactory>(),
						p.GetService<IConsumerFactory>(),
						p.GetService<IMessageSerializer>(),
						p.GetService<IMessageContextProvider<MessageContext>>(),
						p.GetService<RawRabbitConfiguration>().RequestTimeout));
			configureIoc?.Invoke(services);
			var serviceProvider = services.BuildServiceProvider();

			return new BusClient(
				serviceProvider.GetService<IConfigurationEvaluator>(),
				serviceProvider.GetService<ISubscriber<MessageContext>>(),
				serviceProvider.GetService<IPublisher>(),
				serviceProvider.GetService<IResponder<MessageContext>>(),
				serviceProvider.GetService<IRequester>()
			);
		}

		public static BusClient CreateDefault(TimeSpan requestTimeout)
		{
			return CreateDefault(new RawRabbitConfiguration { RequestTimeout = requestTimeout });
		}
	}
}<commit_msg>Add more default methods for BusClientFactory<commit_after>﻿using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Framework.DependencyInjection;
using RabbitMQ.Client;
using RawRabbit.Configuration;
using RawRabbit.Consumer;
using RawRabbit.Consumer.Contract;
using RawRabbit.Consumer.Eventing;
using RawRabbit.Context;
using RawRabbit.Context.Provider;
using RawRabbit.Operations;
using RawRabbit.Operations.Contracts;
using RawRabbit.Serialization;

namespace RawRabbit.Common
{
	public class BusClientFactory
	{
		public static BusClient CreateDefault(RawRabbitConfiguration config, Action<IServiceCollection> configureIoc = null)
		{
			var services = new ServiceCollection();
			services
				.AddSingleton<RawRabbitConfiguration>(provider => config ?? new RawRabbitConfiguration())
				.AddSingleton<IConnectionFactory, ConnectionFactory>(p =>
				{
					var cfg = p.GetService<RawRabbitConfiguration>();
					return new ConnectionFactory
					{
						HostName = cfg.Hostname,
						Password = <PASSWORD>,
						UserName = cfg.Username,
						AutomaticRecoveryEnabled = true,
						TopologyRecoveryEnabled = true,
					};
				})
				.AddTransient<IMessageSerializer, JsonMessageSerializer>()
				.AddTransient<IConsumerFactory, EventingBasicConsumerFactory>()
				.AddSingleton<IMessageContextProvider<MessageContext>, DefaultMessageContextProvider>(
					p => new DefaultMessageContextProvider(() => Task.FromResult(Guid.NewGuid())))
				.AddSingleton<IChannelFactory, ChannelFactory>() //TODO: Should this be one/application?
				.AddTransient<IConfigurationEvaluator, ConfigurationEvaluator>()
				.AddTransient<INamingConvetions, NamingConvetions>()
				.AddTransient<ISubscriber<MessageContext>, Subscriber<MessageContext>>()
				.AddTransient<IPublisher, Publisher<MessageContext>>()
				.AddTransient<IResponder<MessageContext>, Responder<MessageContext>>()
				.AddTransient<IRequester, Requester<MessageContext>>(
					p => new Requester<MessageContext>(
						p.GetService<IChannelFactory>(),
						p.GetService<IConsumerFactory>(),
						p.GetService<IMessageSerializer>(),
						p.GetService<IMessageContextProvider<MessageContext>>(),
						p.GetService<RawRabbitConfiguration>().RequestTimeout));
			configureIoc?.Invoke(services);
			var serviceProvider = services.BuildServiceProvider();

			return CreateDefault(serviceProvider);
		}

		public static BusClient CreateDefault(Action<IServiceCollection> services = null)
		{
			return CreateDefault(null, services);
		}

		public static BusClient CreateDefault(IServiceProvider serviceProvider)
		{
			return new BusClient(
				serviceProvider.GetService<IConfigurationEvaluator>(),
				serviceProvider.GetService<ISubscriber<MessageContext>>(),
				serviceProvider.GetService<IPublisher>(),
				serviceProvider.GetService<IResponder<MessageContext>>(),
				serviceProvider.GetService<IRequester>()
			);
		}

		public static BusClient CreateDefault(TimeSpan requestTimeout)
		{
			return CreateDefault(new RawRabbitConfiguration { RequestTimeout = requestTimeout });
		}
	}
}
{'fraction_non_alphanumeric': 0.10122908842608398, 'fraction_numerical': 0.0, 'mean_word_length': 5.665529010238908, 'pattern_counts': {'":': 0, '<': 76, '<?xml version=': 0, '>': 86, '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': '7307563', 'n_tokens_mistral': 1931, 'n_tokens_neox': 1591, 'n_words': 276}