using Microsoft.Extensions.DependencyInjection; using Pole.Core; using Pole.Core.Channels; using Pole.Core.EventBus; using Pole.Core.Processor; using Pole.Core.Processor.Server; using Pole.Core.Serialization; using Pole.Core.UnitOfWork; using Pole.Core.Utils; using Pole.Core.Utils.Abstraction; using System; using System.Collections.Generic; using System.Text; namespace Microsoft.Extensions.DependencyInjection { public static class PoleServiceCollectionExtensions { public static IServiceCollection AddPole(this IServiceCollection services, Action config) { StartupConfig startupOption = new StartupConfig(services); if (startupOption.PoleOptionsConfig == null) { services.Configure(option => { }); } services.AddSingleton(); services.AddTransient(typeof(IMpscChannel<>), typeof(MpscChannel<>)); services.AddScoped(); services.AddScoped(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); using (var serviceProvider = services.BuildServiceProvider()) { var generatorIdSolver = serviceProvider.GetService(); services.AddSingleton(typeof(ISnowflakeIdGenerator), factory => new SnowflakeIdGenerator(new DateTime(2020, 1, 1), 16, generatorIdSolver.GetGeneratorId())); } services.AddSingleton(); services.AddSingleton(); services.AddHostedService(); config(startupOption); return services; } } }