2024-12-02 13:24:34 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using OnlineAssessment.Common;
|
|
|
|
|
|
using OnlineAssessment.Domain.Models;
|
|
|
|
|
|
|
|
|
|
|
|
namespace OnlineAssessment
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class StartupExtensions
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Register the database connections used by the API with DI.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static IServiceCollection AddDbConnections(this IServiceCollection services, IConfiguration configuration)
|
|
|
|
|
|
{
|
2025-10-27 04:12:41 +00:00
|
|
|
|
string connection = configuration.GetConnectionString("DefaultConnectionString");
|
|
|
|
|
|
//string connection = Security.Decrypt(text);
|
|
|
|
|
|
|
2024-12-02 13:24:34 +00:00
|
|
|
|
return services
|
|
|
|
|
|
.AddEntityFrameworkSqlServer()
|
|
|
|
|
|
.AddDbContextPool<OnlineAssessmentContext>((serviceProvider, optionsBuilder) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
optionsBuilder.UseSqlServer(connection);
|
|
|
|
|
|
optionsBuilder.UseInternalServiceProvider(serviceProvider);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|