using Mediator; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; namespace Toolkit.Foundation { public static class IServiceCollectionExtensions { public static IServiceCollection AddHandler(this IServiceCollection serviceCollection) { serviceCollection.TryAdd(new ServiceDescriptor(typeof(TRequestHandler), typeof(TRequestHandler), ServiceLifetime.Transient)); return serviceCollection; } public static IServiceCollection AddFoundation(this IServiceCollection serviceCollection) { serviceCollection.AddSingleton(provider => new ServiceFactory(provider.GetService, (instanceType, parameters) => ActivatorUtilities.CreateInstance(provider, instanceType, parameters!))); return serviceCollection; } } }