You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132
  1. using Core.Db;
  2. using Microsoft.EntityFrameworkCore;
  3. using System.Reflection;
  4. using AutoMapper;
  5. using Microsoft.Extensions.DependencyInjection;
  6. using Microsoft.AspNetCore.Http;
  7. using Microsoft.Extensions.Configuration;
  8. namespace Api.Start
  9. {
  10. public static class DI
  11. {
  12. public static void RegisterDependencies(this IServiceCollection services, IConfiguration configuration)
  13. {
  14. services.AddDbContext<PanakDbContext>(options => options.UseSqlServer(configuration.GetConnectionString("PanakContext")));
  15. services.AddScoped<DbContext, PanakDbContext>();
  16. services.Scan(scan => scan
  17. .FromAssemblies(typeof(Services.Identity.IAuthService).GetTypeInfo().Assembly)
  18. .AddClasses()
  19. .AsImplementedInterfaces()
  20. .WithScopedLifetime());
  21. services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
  22. var mapperConfig = new MapperConfiguration(mc =>
  23. {
  24. mc.AddProfile(new AutoMapperConfig());
  25. });
  26. var mapper = mapperConfig.CreateMapper();
  27. services.AddSingleton(mapper);
  28. }
  29. }
  30. }