/
Airat
/
ASP.NET
Обзор
Документация
Войти
/
Airat
/
ASP.NET
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
EF/src/PromoCodeFactory.WebHost/Startup.cs
81 строка
3 KB
Айрат Измаилов
modified: EF/src/PromoCodeFactory.Core/Abstractions/Repositories/IRepository.cs
06 ноя 2024, 19:39
06 ноя 2024, 19:39
c4e3369
Код
Авторство
О чём код?
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using PromoCodeFactory.Core.Abstractions.Repositories; using PromoCodeFactory.Core.Domain.Administration; using PromoCodeFactory.Core.Domain.PromoCodeManagement; using PromoCodeFactory.DataAccess.Data; using PromoCodeFactory.DataAccess.Repositories; namespace PromoCodeFactory.WebHost { public class Startup { public IConfiguration Configuration { get; } public Startup(IConfiguration configuration) { Configuration = configuration; } // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddDbContext<AppDbContext>(options => options.UseSqlite(Configuration.GetConnectionString("SqliteConnection"))); services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>)); services.AddScoped<ILoadData, LoadData>(); /* services.AddScoped(typeof(IRepository<Employee>), (x) => new InMemoryRepository<Employee>(FakeDataFactory.Employees)); services.AddScoped(typeof(IRepository<Role>), (x) => new InMemoryRepository<Role>(FakeDataFactory.Roles)); services.AddScoped(typeof(IRepository<Preference>), (x) => new InMemoryRepository<Preference>(FakeDataFactory.Preferences)); services.AddScoped(typeof(IRepository<Customer>), (x) => new InMemoryRepository<Customer>(FakeDataFactory.Customers)); //*/ services.AddOpenApiDocument(options => { options.Title = "PromoCode Factory API Doc"; options.Version = "1.0"; }); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoadData loadData) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseOpenApi(); app.UseSwaggerUi(x => { x.DocExpansion = "list"; }); app.UseHttpsRedirection(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); loadData.LoadDataInDB(); } } }