39 lines
1.6 KiB
C#
39 lines
1.6 KiB
C#
using Azure.Identity;
|
|
using Core.Blueprint.DAL.SQLServer;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Core.Blueprint.SQLServer.Configuration
|
|
{
|
|
/// <summary>
|
|
/// Provides extension methods for configuring SQL Server.
|
|
/// </summary>
|
|
public static class RegisterBlueprint
|
|
{
|
|
/// <summary>
|
|
/// Configures SQL Server services, including the database context and generic repository, for dependency injection.
|
|
/// </summary>
|
|
/// <param name="services">The service collection to which the SQL Server services will be added.</param>
|
|
/// <param name="configuration">The application configuration object for accessing settings such as connection strings.</param>
|
|
/// <returns>An updated <see cref="IServiceCollection"/> with SQL Server services registered.</returns>
|
|
public static IServiceCollection AddSQLServer(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? string.Empty;
|
|
|
|
if (environment != "Local")
|
|
{
|
|
var chainedCredentials = new ChainedTokenCredential(
|
|
new ManagedIdentityCredential(),
|
|
new SharedTokenCacheCredential(),
|
|
new VisualStudioCredential(),
|
|
new VisualStudioCodeCredential()
|
|
);
|
|
}
|
|
|
|
services.AddScoped(typeof(IEntityRepository<,>), typeof(EntityRepository<,>));
|
|
|
|
return services;
|
|
}
|
|
}
|
|
}
|