BotSharp/src/Plugins/BotSharp.Plugin.MongoStorage/MongoStoragePlugin.cs
2023-09-03 14:32:12 -05:00

24 lines
746 B
C#

using BotSharp.Plugin.MongoStorage.Repository;
namespace BotSharp.Plugin.MongoStorage;
public class MongoStoragePlugin : IBotSharpPlugin
{
public void RegisterDI(IServiceCollection services, IConfiguration config)
{
var sp = services.BuildServiceProvider();
var dbSettings = sp.GetRequiredService<BotSharpDatabaseSettings>();
if (dbSettings.Default == "MongoRepository")
{
services.AddScoped((IServiceProvider x) =>
{
var dbSettings = x.GetRequiredService<BotSharpDatabaseSettings>();
return new MongoDbContext(dbSettings.MongoDb);
});
services.AddScoped<IBotSharpRepository, MongoRepository>();
}
}
}