Add project files.
This commit is contained in:
		| @@ -0,0 +1,75 @@ | ||||
| using Azure.Identity; | ||||
| using Core.Blueprint.DAL.Infrastructure.Context; | ||||
| using Core.Blueprint.DAL.Infrastructure.Contracts; | ||||
| using Core.Blueprint.DAL.Infrastructure.Proxies; | ||||
| using Core.Blueprint.DAL.Infrastructure.Repository; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.Extensions.Azure; | ||||
| using Microsoft.Extensions.Configuration; | ||||
| using Microsoft.Extensions.DependencyInjection; | ||||
| using Microsoft.Extensions.Options; | ||||
| using System.Reflection; | ||||
| using Serilog; | ||||
| using Serilog.Events; | ||||
| using Serilog.Exceptions; | ||||
|  | ||||
| namespace Core.Blueprint.DAL.Infrastructure.Configure | ||||
| { | ||||
|     public static class DependencyInjection | ||||
|     { | ||||
|         public static IServiceCollection RegisterInfrastructure(this IServiceCollection services, IConfiguration configuration) | ||||
|         { | ||||
|             var chainedCredentials = new ChainedTokenCredential( | ||||
|                     new ManagedIdentityCredential(), | ||||
|                     new SharedTokenCacheCredential(), | ||||
|                     new VisualStudioCredential(), | ||||
|                     new VisualStudioCodeCredential() | ||||
|                 ); | ||||
|             services.AddAzureClients(cfg => | ||||
|             { | ||||
|                 cfg.AddBlobServiceClient(configuration.GetRequiredSection("Azure:BlobStorage")).WithCredential(chainedCredentials); | ||||
|                 cfg.AddSecretClient(configuration.GetRequiredSection("Azure:KeyVault")).WithCredential(chainedCredentials); | ||||
|             }); | ||||
|  | ||||
|             services.AddDbContext<SqlServerContext>(options => options.UseSqlServer(configuration.GetConnectionString("SQLServerConnString"))); | ||||
|           | ||||
|             // LogFactory | ||||
|             services.ConfigureLogging(); | ||||
|              | ||||
|             //MongoDB | ||||
|             services.Configure<MongoDbSettings>(configuration.GetRequiredSection("MongoDbSettings")); | ||||
|             services.AddScoped<IMongoDbSettings>(serviceProvider => | ||||
|                 serviceProvider.GetRequiredService<IOptions<MongoDbSettings>>().Value); | ||||
|             services.AddScoped<IMongoContext, MongoContext>(); | ||||
|             services.AddScoped(serviceProvider => | ||||
|             { | ||||
|                 var mongoContext = serviceProvider.GetRequiredService<IMongoContext>(); | ||||
|                 return mongoContext.Database; | ||||
|             }); | ||||
|  | ||||
|             services.AddScoped<IProxyBlobStorage, ProxyBlobStorage>(); | ||||
|             services.AddScoped<ISampleImageRepository, SampleImageRepository>(); | ||||
|             services.AddScoped<ISampleItemRepository, SampleItemRepository>(); | ||||
|             services.AddScoped<IBlueprintRepository, BlueprintRepository>(); | ||||
|             services.AddScoped<ISecretRepository, SecretRepository>(); | ||||
|  | ||||
|             return services; | ||||
|         } | ||||
|  | ||||
|         public static void ConfigureLogging(this IServiceCollection services) | ||||
|         { | ||||
|             Log.Logger = new LoggerConfiguration() | ||||
|                 .Enrich.FromLogContext() | ||||
|                 .Enrich.WithMachineName() | ||||
|                 .Enrich.WithProcessId() | ||||
|                 .Enrich.WithThreadId() | ||||
|                 .Enrich.WithProperty("Application", Assembly.GetExecutingAssembly().GetName().Name) | ||||
|                 .Enrich.WithExceptionDetails() | ||||
|                 .MinimumLevel.Is(LogEventLevel.Information) | ||||
|                 .WriteTo.Console() | ||||
|                 .CreateLogger(); | ||||
|  | ||||
|             services.AddSingleton(Log.Logger); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,12 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
|  | ||||
| namespace Core.Blueprint.DAL.Infrastructure.Configure | ||||
| { | ||||
|     class LoggerExtension | ||||
|     { | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sergio Matias Urquin
					Sergio Matias Urquin