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

27 lines
765 B
C#
Raw Normal View History

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
{
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
}
}