Add project files.
This commit is contained in:
		
							
								
								
									
										36
									
								
								Core.Blueprint.DAL.API/Extensions/ConfigurationExtension.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								Core.Blueprint.DAL.API/Extensions/ConfigurationExtension.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,36 @@ | ||||
| using Core.Blueprint.DAL.KeyVault.Contracts; | ||||
| using Core.Blueprint.DAL.KeyVault.Services; | ||||
| using Core.Blueprint.DAL.Mongo.Contracts; | ||||
| using Core.Blueprint.DAL.Mongo.Entities.Collections; | ||||
| using Core.Blueprint.DAL.Mongo.Service; | ||||
| using Core.Blueprint.DAL.SQLServer.Context; | ||||
| using Core.Blueprint.DAL.SQLServer.Contracts; | ||||
| using Core.Blueprint.DAL.Storage.Contracts; | ||||
| using Core.Blueprint.DAL.Storage.Service; | ||||
| using Core.Blueprint.Mongo; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
|  | ||||
| namespace Core.Blueprint.DAL.API.Extensions | ||||
| { | ||||
|     public static class ConfigurationExtension | ||||
|     { | ||||
|         public static IServiceCollection AddDALLayerServices(this IServiceCollection services, IConfiguration configuration) | ||||
|         { | ||||
|             //Mongo | ||||
|             services.AddScoped<IBlueprintService, BlueprintService>(); | ||||
|             services.AddScoped<CollectionRepository<BlueprintCollection>>(); | ||||
|  | ||||
|             //SQL | ||||
|             services.AddDbContext<SqlServerContext>(options => options.UseSqlServer(configuration.GetConnectionString("SQLServer"))); | ||||
|             services.AddScoped<IUserProjectService, UserProjectService>(); | ||||
|  | ||||
|             //Storage | ||||
|             services.AddScoped<IBlobStorageService, BlobStorageService>(); | ||||
|  | ||||
|             //KeyVault | ||||
|             services.AddScoped<IKeyVaultService, KeyVaultService>(); | ||||
|  | ||||
|             return services; | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										71
									
								
								Core.Blueprint.DAL.API/Extensions/SwaggerExtensions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								Core.Blueprint.DAL.API/Extensions/SwaggerExtensions.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,71 @@ | ||||
| using Asp.Versioning.ApiExplorer; | ||||
| using Microsoft.Extensions.Options; | ||||
| using Microsoft.OpenApi.Any; | ||||
| using Swashbuckle.AspNetCore.SwaggerGen; | ||||
| using Swashbuckle.AspNetCore.SwaggerUI; | ||||
|  | ||||
| namespace Core.Blueprint.DAL.API.Extensions | ||||
| { | ||||
|     public static class SwaggerExtensions | ||||
|     { | ||||
|         public static void AddSwagger(this IServiceCollection services) | ||||
|         { | ||||
|             services.AddEndpointsApiExplorer(); | ||||
|             services.AddSwaggerGen(); | ||||
|             services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>(); | ||||
|         } | ||||
|  | ||||
|         public static void ConfigureSwagger(this WebApplication app) | ||||
|         { | ||||
|             app.UseSwagger(); | ||||
|             app.UseSwaggerUI(options => | ||||
|             { | ||||
|                 foreach (var version in app.DescribeApiVersions().Select(version => version.GroupName)) | ||||
|                     options.SwaggerEndpoint($"/swagger/{version}/swagger.json", version); | ||||
|  | ||||
|                 options.DisplayRequestDuration(); | ||||
|                 options.EnableTryItOutByDefault(); | ||||
|                 options.DocExpansion(DocExpansion.None); | ||||
|             }); | ||||
|         } | ||||
|         public static IServiceCollection AddVersioning(this IServiceCollection services) | ||||
|         { | ||||
|             services.AddApiVersioning(options => options.ReportApiVersions = true) | ||||
|                    .AddApiExplorer(options => | ||||
|                    { | ||||
|                        options.GroupNameFormat = "'v'VVV"; | ||||
|                        options.SubstituteApiVersionInUrl = true; | ||||
|                    }); | ||||
|  | ||||
|             return services; | ||||
|         } | ||||
|     } | ||||
|     public class ConfigureSwaggerOptions : IConfigureOptions<SwaggerGenOptions> | ||||
|     { | ||||
|         private readonly IApiVersionDescriptionProvider _provider; | ||||
|  | ||||
|         public ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider) | ||||
|         { | ||||
|             _provider = provider; | ||||
|         } | ||||
|  | ||||
|         public void Configure(SwaggerGenOptions options) | ||||
|         { | ||||
|             foreach (var description in _provider.ApiVersionDescriptions) | ||||
|                 options.SwaggerDoc(description.GroupName, new() | ||||
|                 { | ||||
|                     Title = AppDomain.CurrentDomain.FriendlyName, | ||||
|                     Version = description.ApiVersion.ToString() | ||||
|                 }); | ||||
|  | ||||
|             //Map ALL Values Format TODO | ||||
|             options.MapType<DateOnly>(() => new() | ||||
|             { | ||||
|                 Format = "date", | ||||
|                 Example = new OpenApiString(DateOnly.MinValue.ToString()) | ||||
|             }); | ||||
|  | ||||
|             options.CustomSchemaIds(type => type.ToString().Replace("+", ".")); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sergio Matias Urquin
					Sergio Matias Urquin