BotSharp/src/Infrastructure/BotSharp.Core/BotSharpServiceCollectionExtensions.cs

58 lines
1.6 KiB
C#
Raw Normal View History

2023-06-03 02:07:30 +00:00
using BotSharp.Abstraction.Conversations;
using BotSharp.Core.Conversations;
using BotSharp.Core.Repository;
2023-05-27 01:58:31 +00:00
using BotSharp.Core.Services;
2023-06-03 02:07:30 +00:00
using EntityFrameworkCore.BootKit;
2023-05-27 01:58:31 +00:00
using Microsoft.AspNetCore.Builder;
2023-06-03 02:07:30 +00:00
using Microsoft.Extensions.Configuration;
2023-05-27 01:58:31 +00:00
using Microsoft.Extensions.DependencyInjection;
namespace BotSharp.Core;
public static class BotSharpServiceCollectionExtensions
{
public static IServiceCollection AddBotSharp(this IServiceCollection services)
{
services.AddScoped<IPlatformMidware, PlatformMidware>();
2023-06-03 02:07:30 +00:00
services.AddSingleton<IConversationService, ConversationService>();
2023-05-27 01:58:31 +00:00
return services;
}
public static void ConfigureBotSharp(this IServiceCollection services)
{
}
public static IApplicationBuilder UseBotSharp(this IApplicationBuilder app)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
return app;
}
2023-06-03 02:07:30 +00:00
public static void RegisterRepository(this IServiceCollection services, IConfiguration config)
{
var databaseSettings = new DatabaseSettings();
config.Bind("Database", databaseSettings);
services.AddSingleton((IServiceProvider x) =>
{
return databaseSettings;
});
var myDatabaseSettings = new MyDatabaseSettings();
config.Bind("Database", myDatabaseSettings);
services.AddSingleton((IServiceProvider x) =>
{
return databaseSettings;
});
services.AddScoped((IServiceProvider x) =>
{
return DataContextHelper.GetDbContext<MongoDbContext>(myDatabaseSettings, x);
});
}
2023-05-27 01:58:31 +00:00
}