|
| 1 | +using AutoMapper; |
| 2 | +using Microsoft.AspNetCore.Builder; |
| 3 | +using Microsoft.EntityFrameworkCore; |
| 4 | +using Microsoft.Extensions.Configuration; |
| 5 | +using Microsoft.Extensions.DependencyInjection; |
| 6 | +using Supermarket.Domain.Services; |
| 7 | +using Supermarket.Domain.Services.Contracts; |
| 8 | +using Supermarket.Persistent.Context; |
| 9 | +using Supermarket.Persistent.Contracts; |
| 10 | +using Supermarket.Persistent.Repositories; |
| 11 | +using Swashbuckle.AspNetCore.Swagger; |
| 12 | + |
| 13 | +namespace Supermarket.Extensions |
| 14 | +{ |
| 15 | + public static class ServiceExtensions |
| 16 | + { |
| 17 | + public static void ConfigureCors(this IServiceCollection services) |
| 18 | + { |
| 19 | + services.AddCors(options => |
| 20 | + { |
| 21 | + options.AddPolicy("CorsPolicy", |
| 22 | + builder => builder.AllowAnyOrigin() |
| 23 | + .AllowAnyMethod() |
| 24 | + .AllowAnyHeader() |
| 25 | + .AllowCredentials()); |
| 26 | + }); |
| 27 | + } |
| 28 | + |
| 29 | + public static void ConfigureIISIntegration(this IServiceCollection services) |
| 30 | + { |
| 31 | + services.Configure<IISOptions>(options => { }); |
| 32 | + } |
| 33 | + |
| 34 | + public static void ConfigureMSSQLContext(this IServiceCollection services, IConfiguration configuration) |
| 35 | + { |
| 36 | + services.AddDbContext<RepositoryContext>(options => |
| 37 | + { |
| 38 | + options.UseInMemoryDatabase("supermarket-api-in-memory"); |
| 39 | + }); |
| 40 | + } |
| 41 | + |
| 42 | + public static void ConfigureRepositoryWrapper(this IServiceCollection services) |
| 43 | + { |
| 44 | + services.AddScoped<IRepositoryWrapper, RepositoryWrapper>(); |
| 45 | + } |
| 46 | + |
| 47 | + public static void ConfigureServicesWrapper(this IServiceCollection services) |
| 48 | + { |
| 49 | + services.AddScoped<IServiceWrapper, ServiceWrapper>(); |
| 50 | + } |
| 51 | + |
| 52 | + public static void ConfigureAutoMapper(this IServiceCollection services) |
| 53 | + { |
| 54 | + services.AddAutoMapper(); |
| 55 | + } |
| 56 | + |
| 57 | + public static void ConfigureSwagger(this IServiceCollection services) |
| 58 | + { |
| 59 | + services.AddSwaggerGen(c => |
| 60 | + { |
| 61 | + c.SwaggerDoc("v1", new Info |
| 62 | + { |
| 63 | + Title = "Supermarket API", |
| 64 | + Version = "v1", |
| 65 | + Description = "A simple example ASP.NET Core Web API", |
| 66 | + TermsOfService = "None", |
| 67 | + Contact = new Contact |
| 68 | + { |
| 69 | + Name = "Mathavan N", |
| 70 | + Email = "mathavan@gmail.com", |
| 71 | + Url = "https://github.com/Mathavana" |
| 72 | + }, |
| 73 | + License = new License |
| 74 | + { |
| 75 | + Name = "Use under LICX", |
| 76 | + Url = "https://example.com/license" |
| 77 | + } |
| 78 | + }); |
| 79 | + }); |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments