BotSharp/src/Plugins/BotSharp.Plugin.MongoStorage/MongoStoragePlugin.cs

33 lines
1.2 KiB
C#
Raw Normal View History

2024-04-12 15:00:55 +00:00
using BotSharp.Abstraction.Repositories.Enums;
2023-09-01 22:33:36 +00:00
using BotSharp.Plugin.MongoStorage.Repository;
namespace BotSharp.Plugin.MongoStorage;
2023-10-11 04:11:06 +00:00
/// <summary>
/// MongoDB as the repository
/// </summary>
2023-09-01 22:33:36 +00:00
public class MongoStoragePlugin : IBotSharpPlugin
{
2024-01-12 22:20:22 +00:00
public string Id => "058094a7-4ad3-4284-b94d-ac1373cf63d8";
2023-10-12 11:36:36 +00:00
public string Name => "MongoDB Storage";
2024-01-16 19:23:45 +00:00
public string Description => "MongoDB as the repository, store data in document DB. It is suitable for production-level systems.";
2023-12-26 03:16:41 +00:00
public string IconUrl => "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRrFrT-_0VYV4PraApwSUmsf4pBGWgvLTaLZGUd7942FxjErsA5iaL4n5Q7CplOmVtwEQ&usqp=CAU";
2023-10-12 11:36:36 +00:00
2023-09-01 22:33:36 +00:00
public void RegisterDI(IServiceCollection services, IConfiguration config)
{
2023-09-09 20:30:39 +00:00
var dbSettings = new BotSharpDatabaseSettings();
config.Bind("Database", dbSettings);
2024-04-12 15:00:55 +00:00
if (dbSettings.Default == RepositoryEnum.MongoRepository)
2023-09-02 05:10:46 +00:00
{
2023-09-03 19:32:12 +00:00
services.AddScoped((IServiceProvider x) =>
{
var dbSettings = x.GetRequiredService<BotSharpDatabaseSettings>();
2023-09-12 22:34:50 +00:00
return new MongoDbContext(dbSettings);
2023-09-03 19:32:12 +00:00
});
2023-09-01 22:33:36 +00:00
2023-09-03 19:32:12 +00:00
services.AddScoped<IBotSharpRepository, MongoRepository>();
}
2023-09-01 22:33:36 +00:00
}
}