Files
caliverse_server/UGQDataAccess/Extensions/UGQDataAccessExtentions.cs
2025-05-01 07:20:41 +09:00

80 lines
2.6 KiB
C#

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<IServiceCollection> AddUGQDataAccess(this IServiceCollection services, IConfiguration configuration)
{
services.Configure<UGQDatabaseSettings>(configuration.GetSection("UGQDatabase"));
services.AddSingleton<IMongoClient>(s => {
var UGQDatabase = configuration.GetSection("UGQDatabase").Get<UGQDatabaseSettings>();
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<QuestAcceptedRepository>();
services.AddSingleton<QuestCompletedRepository>();
services.AddSingleton<QuestAbortedRepository>();
services.AddSingleton<QuestIdSequenceRepository>();
services.AddSingleton<QuestContentRepository>();
services.AddSingleton<QuestDialogRepository>();
services.AddSingleton<AccountRepository>();
services.AddSingleton<LikeRepository>();
services.AddSingleton<BookmarkRepository>();
services.AddSingleton<NpcNameRepository>();
services.AddSingleton<CreatorPointHistoryRepository>();
services.AddSingleton<GameQuestDataRepository>();
services.AddSingleton<ReportRepository>();
services.AddSingleton<AdminAccountRepository>();
services.AddSingleton<AdminService>();
services.AddSingleton<AccountService>();
services.AddSingleton<QuestEditorService>();
services.AddSingleton<InGameService>();
services.AddSingleton<UgqMetaGenerateService>();
services.AddSingleton<ReserveAccountGradeRepository>();
var provider = services.BuildServiceProvider();
var questIdSequenceRepository = provider.GetService<QuestIdSequenceRepository>();
if (questIdSequenceRepository != null)
await questIdSequenceRepository.init();
return services;
}
}