<commit_before>using System;
using System.Runtime.CompilerServices;
using Microsoft.Extensions.DependencyInjection;

namespace DotVVM.Framework.Configuration
{
    public class ServiceLocator
    {
        private IServiceCollection serviceCollection;
        private IServiceProvider serviceProvider;

        public ServiceLocator(IServiceProvider serviceProvider)
        {
            this.serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
        }

        public ServiceLocator(IServiceCollection serviceCollection)
        {
            this.serviceCollection = serviceCollection ?? throw new ArgumentNullException(nameof(serviceCollection));
        }

        public IServiceProvider GetServiceProvider()
        {
            if (serviceProvider == null)
            {
                serviceProvider = BuildServiceProvider();
                serviceCollection = null;
            }
            return serviceProvider;
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        private IServiceProvider BuildServiceProvider()
        {
            return serviceCollection.BuildServiceProvider();
        }

        public T GetService<T>()
            => GetServiceProvider().GetService<T>();
    }
}<commit_msg>Added workaround for breaking change in DependencyInjection<commit_after>using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using Microsoft.Extensions.DependencyInjection;

namespace DotVVM.Framework.Configuration
{
    public class ServiceLocator
    {
        private IServiceCollection serviceCollection;
        private IServiceProvider serviceProvider;

        public ServiceLocator(IServiceProvider serviceProvider)
        {
            this.serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
        }

        public ServiceLocator(IServiceCollection serviceCollection)
        {
            this.serviceCollection = serviceCollection ?? throw new ArgumentNullException(nameof(serviceCollection));
        }

        public IServiceProvider GetServiceProvider()
        {
            if (serviceProvider == null)
            {
                serviceProvider = BuildServiceProvider();
                serviceCollection = null;
            }
            return serviceProvider;
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        private IServiceProvider BuildServiceProvider()
        {
            return BuildServiceProvider(serviceCollection);
        }

        public T GetService<T>()
            => GetServiceProvider().GetService<T>();

        /// <summary>
        /// Workaround for breaking change introduced in https://github.com/aspnet/DependencyInjection/pull/616
        /// In Microsoft.Extensions.DependencyInjection 2.0 signature of <see cref="ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection)"/> has been changed slightly causing <see cref="MissingMethodException"/>.
        /// Lets bind it dynamically.
        /// Source: https://github.com/peachpiecompiler/peachpie/blob/eb9213f174fa909459ad0137ff996876eac2ac4c
        /// </summary>
        private static IServiceProvider BuildServiceProvider(IServiceCollection services)
        {
            // Template: return ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(services);

            var t = typeof(ServiceCollectionContainerBuilderExtensions).GetTypeInfo();
            var BuildServiceProviderMethod = t.GetMethod(nameof(BuildServiceProvider), new Type[] { typeof(IServiceCollection) });
            Debug.Assert(BuildServiceProviderMethod != null);

            return (IServiceProvider)BuildServiceProviderMethod.Invoke(null, new[] { services });
        }
    }
}
{'fraction_non_alphanumeric': 0.07568988173455979, 'fraction_numerical': 0.00788436268068331, 'mean_word_length': 2.863959390862944, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 2, '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': '6124101', 'n_tokens_mistral': 865, 'n_tokens_neox': 825, 'n_words': 172}