<commit_before>using System;
using System.IO;
using Autofac;
using gifty.Shared.CQRS.Handlers;
using gifty.Shared.CQRS.Contracts;
using gifty.Shared.IoC;
using Microsoft.AspNetCore.Hosting;
using RawRabbit;
using RawRabbit.vNext;

namespace gifty.Shared.Builders
{
    public class ServiceBuilder : IServiceBuilder, IAutofacServiceBuilder, IRabbitMqServiceBuilder
    {
        private IWebHostBuilder _webHostBuilder;

        private IWebHost _webHost;
        private ICustomDependencyResolver _customDependencyResolver;
        private IBusClient _busClient;
        private string _queueName;

        public ServiceBuilder(IWebHostBuilder webHostBuilder)
        {
            _webHostBuilder = webHostBuilder;
        }

        public static ServiceBuilder CreateDefault<TStartup>() where TStartup : class
        {
            var webHostBuilder  = new WebHostBuilder()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseKestrel()
                .UseStartup<TStartup>();

            return new ServiceBuilder(webHostBuilder);
        }

        IAutofacServiceBuilder IServiceBuilder.WithPort(int port)
        {
            _webHostBuilder.UseUrls($"http://*:{port}");
            return this;
        }

        IRabbitMqServiceBuilder IAutofacServiceBuilder.WithAutofac(Func<ContainerBuilder,ICustomDependencyResolver> registrations)
        {
            var containerBuilder = new ContainerBuilder();
            _customDependencyResolver = registrations(containerBuilder);

            return this;
        }

        IRabbitMqServiceBuilder IRabbitMqServiceBuilder.WithRabbitMq(string queueName)
        {
            _busClient = BusClientFactory.CreateDefault();
            _queueName = queueName;

            return this;
        }

        IRabbitMqServiceBuilder IRabbitMqServiceBuilder.SubscribeToCommand<TCommand>()
        {
            _busClient.SubscribeAsync<TCommand>(async (command, context) => 
            {
                var commandHandler = _customDependencyResolver.Resolve<ICommandHandler<TCommand>>();
                await commandHandler.HandleAsync(command);
            }, cfg => cfg.WithQueue(q => q.WithName(_queueName)));

            return this;
        }

        IRabbitMqServiceBuilder IRabbitMqServiceBuilder.SubscribeToEvent<TEvent>()
        {
            _busClient.SubscribeAsync<TEvent>(async (@event, context) => 
            {
                var commandHandler = _customDependencyResolver.Resolve<IEventHandler<TEvent>>();
                await commandHandler.HandleAsync(@event);
            }, cfg => cfg.WithQueue(q => q.WithName(_queueName)));

            return this;
        }

        IServiceBuilder IRabbitMqServiceBuilder.Build()
        {
            _webHost = _webHostBuilder.Build();
            return this;
        }

        void IServiceBuilder.Run()
        {
            _webHost.Run();
        }
    }
}<commit_msg>chenged return type in CreateDefault method in ServiceBuilder<commit_after>using System;
using System.IO;
using Autofac;
using gifty.Shared.CQRS.Handlers;
using gifty.Shared.CQRS.Contracts;
using gifty.Shared.IoC;
using Microsoft.AspNetCore.Hosting;
using RawRabbit;
using RawRabbit.vNext;

namespace gifty.Shared.Builders
{
    public class ServiceBuilder : IServiceBuilder, IAutofacServiceBuilder, IRabbitMqServiceBuilder
    {
        private IWebHostBuilder _webHostBuilder;

        private IWebHost _webHost;
        private ICustomDependencyResolver _customDependencyResolver;
        private IBusClient _busClient;
        private string _queueName;

        public ServiceBuilder(IWebHostBuilder webHostBuilder)
        {
            _webHostBuilder = webHostBuilder;
        }

        public static IServiceBuilder CreateDefault<TStartup>() where TStartup : class
        {
            var webHostBuilder  = new WebHostBuilder()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseKestrel()
                .UseStartup<TStartup>();

            return new ServiceBuilder(webHostBuilder);
        }

        IAutofacServiceBuilder IServiceBuilder.WithPort(int port)
        {
            _webHostBuilder.UseUrls($"http://*:{port}");
            return this;
        }

        IRabbitMqServiceBuilder IAutofacServiceBuilder.WithAutofac(Func<ContainerBuilder,ICustomDependencyResolver> registrations)
        {
            var containerBuilder = new ContainerBuilder();
            _customDependencyResolver = registrations(containerBuilder);

            return this;
        }

        IRabbitMqServiceBuilder IRabbitMqServiceBuilder.WithRabbitMq(string queueName)
        {
            _busClient = BusClientFactory.CreateDefault();
            _queueName = queueName;

            return this;
        }

        IRabbitMqServiceBuilder IRabbitMqServiceBuilder.SubscribeToCommand<TCommand>()
        {
            _busClient.SubscribeAsync<TCommand>(async (command, context) => 
            {
                var commandHandler = _customDependencyResolver.Resolve<ICommandHandler<TCommand>>();
                await commandHandler.HandleAsync(command);
            }, cfg => cfg.WithQueue(q => q.WithName(_queueName)));

            return this;
        }

        IRabbitMqServiceBuilder IRabbitMqServiceBuilder.SubscribeToEvent<TEvent>()
        {
            _busClient.SubscribeAsync<TEvent>(async (@event, context) => 
            {
                var commandHandler = _customDependencyResolver.Resolve<IEventHandler<TEvent>>();
                await commandHandler.HandleAsync(@event);
            }, cfg => cfg.WithQueue(q => q.WithName(_queueName)));

            return this;
        }

        IServiceBuilder IRabbitMqServiceBuilder.Build()
        {
            _webHost = _webHostBuilder.Build();
            return this;
        }

        void IServiceBuilder.Run()
        {
            _webHost.Run();
        }
    }
}
{'fraction_non_alphanumeric': 0.07909413554165963, 'fraction_numerical': 0.0, 'mean_word_length': 2.370159453302961, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 37, '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': '4867744', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1514, 'n_words': 263}