using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using PhonebookService.Domain.Repositories;
using PhonebookService.Infrastructure.Repositories;
namespace PhonebookService.Infrastructure;
///
/// Extension class that helps to setup infrastructure layer
///
public static class PhonebookInfrastructureExtensions
{
///
/// Configure infrastructure layer
///
/// Collection of webapp services
/// Webapp configuration entity
/// If set true, EF will not hide personal data (e.g. passwords) when logging. Use only on debug!
public static IServiceCollection ConfigureInfrastructure(this IServiceCollection services, IConfiguration configuration, bool enableSensitiveDataLogging = false)
{
services.AddDbContext(options =>
{
options.UseInMemoryDatabase("PhonebookDatabase");
// options.UseSqlServer(configuration.GetConnectionString("PhonebookDatabase"));
if (enableSensitiveDataLogging)
options.EnableSensitiveDataLogging();
});
services.AddScoped();
return services;
}
}