Example #1
0
        /// <summary>
        /// Activating Swagger middlewares.
        /// </summary>
        /// <param name="app"></param>
        private void AppSwagger(IApplicationBuilder app)
        {
            var swaggerData = ConfigurationTransfer.GetObject <SwaggerSettings>(Configuration);

            app.UseSwagger();
            app.UseSwaggerUI(op => op.SwaggerEndpoint($"/swagger/{swaggerData?.Version}/swagger.json", swaggerData?.Title));
        }
Example #2
0
        public static void AddSwagger(this IServiceCollection services, IConfiguration configuration)
        {
            var swaggerData = ConfigurationTransfer.GetObject <SwaggerSettings>(configuration);

            _ = services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc(swaggerData.Version,
                             new OpenApiInfo
                {
                    Title       = swaggerData.Title,
                    Version     = swaggerData.Version,
                    Description = swaggerData?.Description,
                    Contact     = new OpenApiContact
                    {
                        Name  = swaggerData?.Contact?.Name,
                        Email = swaggerData?.Contact?.Email,
                        Url   = new Uri(swaggerData?.Contact?.Url)
                    }
                });

                // Set the comments path for the Swagger JSON and UI (Properties > Build > set 'XML documentation file').
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
            });
        }
Example #3
0
        /// <summary>
        /// Add Policies to Cors to accept requests from another specifics domains.
        /// It's a Access-Control-Allow-Origin.
        /// </summary>
        /// <param name="services"></param>
        public static void AddCorsSettings(this IServiceCollection services, IConfiguration configuration)
        {
            var corsData = ConfigurationTransfer.GetObject <CorsSettings>(configuration);

            services.AddCors(options =>
            {
                options.AddPolicy(name: corsData.Key, builder =>
                {
                    builder.WithOrigins(corsData.EndpointAllowed);
                });
            });
        }
Example #4
0
        /// <summary>
        /// Activing Cors middlewares.
        /// </summary>
        /// <param name="app"></param>
        private void AppCors(IApplicationBuilder app)
        {
            var corsData = ConfigurationTransfer.GetObject <CorsSettings>(Configuration);

            app.UseCors(corsData.Key);
        }