<commit_before>﻿using Microsoft.Extensions.DependencyInjection;
using System;
using System.Threading.Tasks;

namespace DragonSpark.Composition.Construction;

sealed class ServiceScopeFactory : IServiceScopeFactory
{
	readonly IServiceScopeFactory _factory;

	public ServiceScopeFactory(IServiceScopeFactory factory) => _factory = factory;

	public IServiceScope CreateScope() => new Scope(_factory.CreateAsyncScope());

	sealed class Scope : IServiceScope, IAsyncDisposable
	{
		readonly AsyncServiceScope _scope;

		public Scope(AsyncServiceScope scope)
			: this(scope, new ActivationAwareServiceProvider(scope.ServiceProvider)) {}

		public Scope(AsyncServiceScope scope, IServiceProvider provider)
		{
			_scope          = scope;
			ServiceProvider = provider;
		}

		public IServiceProvider ServiceProvider { get; }

		public void Dispose()
		{
			_scope.Dispose();
		}

		public ValueTask DisposeAsync() => _scope.DisposeAsync();
	}
}<commit_msg>Workaround for now<commit_after>﻿using Microsoft.Extensions.DependencyInjection;
using System;
using System.Threading.Tasks;

namespace DragonSpark.Composition.Construction;

sealed class ServiceScopeFactory : IServiceScopeFactory
{
	readonly IServiceScopeFactory _factory;

	public ServiceScopeFactory(IServiceScopeFactory factory) => _factory = factory;

	public IServiceScope CreateScope() => new Scope(_factory.CreateAsyncScope());

	sealed class Scope : IServiceScope, IAsyncDisposable
	{
		readonly AsyncServiceScope _scope;

		public Scope(AsyncServiceScope scope)
			: this(scope, new ActivationAwareServiceProvider(scope.ServiceProvider)) {}

		public Scope(AsyncServiceScope scope, IServiceProvider provider)
		{
			_scope          = scope;
			ServiceProvider = provider;
		}

		public IServiceProvider ServiceProvider { get; }

		public void Dispose()
		{
			_scope.Dispose();
		}

		public async ValueTask DisposeAsync()
		{
			try
			{
				await _scope.DisposeAsync();
			}
			catch (InvalidOperationException) // ISSUE: LightInject: https://github.com/seesharper/LightInject/issues/577
			{
				//Dispose();
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.08576904647819837, 'fraction_numerical': 0.0014374700527072352, 'mean_word_length': 4.948717948717949, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 1, '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': '934672', 'n_tokens_mistral': 665, 'n_tokens_neox': 583, 'n_words': 131}