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
|
|
|
|
|
{
|
2023-10-12 11:36:36 +00:00
|
|
|
public string Name => "MongoDB Storage";
|
2023-12-26 03:16:41 +00:00
|
|
|
public string Description => "MongoDB as the repository, store data in document.";
|
|
|
|
|
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);
|
|
|
|
|
|
2023-09-03 19:32:12 +00:00
|
|
|
if (dbSettings.Default == "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
|
|
|
}
|
|
|
|
|
}
|