// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //Custom code ServiceExtensions.AddCors(services); services.AddIISIntegration(); services.AddMySqlContext(Configuration); services.AddRepositoryWrapper(Configuration); services.AddHttpContextAccessor(); services.AddAutomapper(); services.AddScoped <ApiExceptionFilter>(); // configure basic authentication services.AddAuthentication("BasicAuthentication") .AddScheme <AuthenticationSchemeOptions, BasicAuthenticationHandler>("BasicAuthentication", null); // services.AddJwtTokenService(Configuration); // services.AddEmailService(Configuration); // code for api versioning services.AddApiVersioning(o => { o.ReportApiVersions = true; o.AssumeDefaultVersionWhenUnspecified = true; o.DefaultApiVersion = new ApiVersion(1, 0); // o.UseApiBehavior = false; }); //Code for user type based authorization of API services.AddAuthorizationPolicy(); services.AddControllers(); //Register the swagger services services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "SwaggerReport", Version = "v1", Description = "Joho Web API List" }); c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Description = "JWT Authorization header using the Bearer scheme (Example: 'Bearer 12345abcdef')", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey, Scheme = "Bearer" }); c.AddSecurityRequirement(new OpenApiSecurityRequirement { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" } }, Array.Empty <string>() } }); c.OperationFilter <CustomHeaderSwaggerAttribute>(); //var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; //var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); //c.IncludeXmlComments(xmlPath); }); services.AddCustomBadRequset(); //Custom code ends }