using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Configuration; using MongoDB.Driver; using ServerCommon; using UGQDataAccess.Settings; using UGQDataAccess.Repository; using UGQDataAccess.Service; using UGQDatabase.Models; namespace UGQDataAccess.Extensions; public static class UGQDataAccessExtentions { public static async Task AddUGQDataAccess(this IServiceCollection services, IConfiguration configuration) { services.Configure(configuration.GetSection("UGQDatabase")); services.AddSingleton(s => { var UGQDatabase = configuration.GetSection("UGQDatabase").Get(); if (UGQDatabase == null) throw new Exception("mongodb config error"); var settings = MongoClientSettings.FromConnectionString(UGQDatabase.ConnectionString); settings.MinConnectionPoolSize = UGQDatabase.MinConnectionPoolSize; settings.MaxConnectionPoolSize = UGQDatabase.MaxConnectionPoolSize; settings.WaitQueueTimeout = TimeSpan.FromSeconds(UGQDatabase.WaitQueueTimeoutSecs); return new MongoClient(settings); }); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); var provider = services.BuildServiceProvider(); var questIdSequenceRepository = provider.GetService(); if (questIdSequenceRepository != null) await questIdSequenceRepository.init(); return services; } }