<commit_before>﻿using Handyman.AspNetCore.ApiVersioning.Abstractions;
using Handyman.AspNetCore.ApiVersioning.ModelBinding;
using Handyman.AspNetCore.ApiVersioning.Routing;
using Handyman.AspNetCore.ApiVersioning.Schemes.MajorMinorPreRelease;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System;

namespace Handyman.AspNetCore.ApiVersioning
{
    public static class ServiceCollectionExtensions
    {
        public static IServiceCollection AddApiVersioning(this IServiceCollection services)
        {
            return services.AddApiVersioning(delegate { });
        }

        public static IServiceCollection AddApiVersioning(this IServiceCollection services, Action<ApiVersioningOptions> configureAction)
        {
            var options = new ApiVersioningOptions { ApiVersionParserType = typeof(MajorMinorPreReleaseApiVersionParser) };

            configureAction.Invoke(options);

            services.AddSingleton<ApiVersionModelBinder>();
            services.AddSingleton<IActionDescriptorProvider, ApiVersionDescriptorProvider>();
            services.TryAddSingleton(typeof(IApiVersionParser), options.ApiVersionParserType);
            services.TryAddSingleton<IApiVersionReader, QueryStringApiVersionReader>();
            services.AddControllers(mvcOptions => mvcOptions.ModelBinderProviders.Insert(0, new ApiVersionModelBinderProvider()));
            services.AddSingleton<MatcherPolicy, ApiVersionEndpointMatcherPolicy>();

            return services;
        }
    }
}<commit_msg>added api version service configuration sentinel<commit_after>﻿using Handyman.AspNetCore.ApiVersioning.Abstractions;
using Handyman.AspNetCore.ApiVersioning.ModelBinding;
using Handyman.AspNetCore.ApiVersioning.Routing;
using Handyman.AspNetCore.ApiVersioning.Schemes.MajorMinorPreRelease;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System;
using System.Linq;

namespace Handyman.AspNetCore.ApiVersioning
{
    public static class ServiceCollectionExtensions
    {
        public static IServiceCollection AddApiVersioning(this IServiceCollection services)
        {
            return services.AddApiVersioning(delegate { });
        }

        public static IServiceCollection AddApiVersioning(this IServiceCollection services, Action<ApiVersioningOptions> configureAction)
        {
            if (services.Any(x => x.ServiceType == typeof(Sentinel)))
                throw new InvalidOperationException("Api versioning has already been added.");

            services.AddTransient<Sentinel>();

            var options = new ApiVersioningOptions { ApiVersionParserType = typeof(MajorMinorPreReleaseApiVersionParser) };

            configureAction.Invoke(options);

            services.AddSingleton<ApiVersionModelBinder>();
            services.AddSingleton<IActionDescriptorProvider, ApiVersionDescriptorProvider>();
            services.TryAddSingleton(typeof(IApiVersionParser), options.ApiVersionParserType);
            services.TryAddSingleton<IApiVersionReader, QueryStringApiVersionReader>();
            services.AddControllers(mvcOptions => mvcOptions.ModelBinderProviders.Insert(0, new ApiVersionModelBinderProvider()));
            services.AddSingleton<MatcherPolicy, ApiVersionEndpointMatcherPolicy>();

            return services;
        }

        private class Sentinel { }
    }
}
{'fraction_non_alphanumeric': 0.07364341085271318, 'fraction_numerical': 0.0005537098560354374, 'mean_word_length': 4.328908554572271, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 17, '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': '983940', 'n_tokens_mistral': 856, 'n_tokens_neox': 881, 'n_words': 147}