|
- using Core.Db;
- using Microsoft.EntityFrameworkCore;
- using System.Reflection;
- using AutoMapper;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Configuration;
-
- namespace Api.Start
- {
- public static class DI
- {
- public static void RegisterDependencies(this IServiceCollection services, IConfiguration configuration)
- {
- services.AddDbContext<PanakDbContext>(options => options.UseSqlServer(configuration.GetConnectionString("PanakContext")));
- services.AddScoped<DbContext, PanakDbContext>();
- services.Scan(scan => scan
- .FromAssemblies(typeof(Services.Identity.IAuthService).GetTypeInfo().Assembly)
- .AddClasses()
- .AsImplementedInterfaces()
- .WithScopedLifetime());
- services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
- var mapperConfig = new MapperConfiguration(mc =>
- {
- mc.AddProfile(new AutoMapperConfig());
- });
- var mapper = mapperConfig.CreateMapper();
- services.AddSingleton(mapper);
-
- }
- }
- }
|