39 lines
1.5 KiB
C#
39 lines
1.5 KiB
C#
using DigitalData.TaskFlow.Application.Common.Interfaces;
|
|
using DigitalData.TaskFlow.Infrastructure.Options;
|
|
using DigitalData.TaskFlow.Infrastructure.Persistence;
|
|
using DigitalData.TaskFlow.Infrastructure.Repositories;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace DigitalData.TaskFlow.Infrastructure;
|
|
|
|
public static class DependencyInjection
|
|
{
|
|
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
var connectionString = configuration.GetConnectionString("TaskFlowDb");
|
|
var databaseOptions = configuration.GetSection(DatabaseOptions.SectionName).Get<DatabaseOptions>() ?? new DatabaseOptions();
|
|
|
|
if (string.IsNullOrWhiteSpace(connectionString))
|
|
{
|
|
throw new InvalidOperationException("Connection string 'TaskFlowDb' is not configured.");
|
|
}
|
|
|
|
services.AddDbContext<TaskFlowDbContext>(options =>
|
|
{
|
|
options.UseSqlServer(connectionString, sqlOptions =>
|
|
{
|
|
sqlOptions.CommandTimeout(databaseOptions.CommandTimeoutSeconds);
|
|
});
|
|
});
|
|
|
|
services.Configure<DatabaseOptions>(configuration.GetSection(DatabaseOptions.SectionName));
|
|
|
|
services.AddScoped<IWorkflowRepository, WorkflowRepository>();
|
|
services.AddScoped<IDocumentRepository, DocumentRepository>();
|
|
|
|
return services;
|
|
}
|
|
}
|