Update on the injection of "HttpContext"
This commit is contained in:
@@ -12,8 +12,7 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
|
||||
public IdentityService(ClaimsPrincipal user)
|
||||
{
|
||||
if (user != null
|
||||
&& user.Claims.Any())
|
||||
if (user != null && user.Claims.Any())
|
||||
{
|
||||
var claims = user.Claims;
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ namespace skydiveLogs_api.Ioc
|
||||
|
||||
_services.AddSingleton<ICacheService, CacheService>();
|
||||
_services.AddScoped<IIdentityService, IdentityService>();
|
||||
|
||||
_services.AddScoped<ClaimsPrincipal>(s => s.GetService<IHttpContextAccessor>()?.HttpContext.User);
|
||||
|
||||
_services.AddScoped<IAircraftRepository, AircraftRepository>();
|
||||
|
||||
@@ -6,7 +6,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -49,8 +49,6 @@ namespace skydiveLogs_api
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddMvc(options => { options.EnableEndpointRouting = false; });
|
||||
//.SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
|
||||
|
||||
services.AddHttpContextAccessor();
|
||||
|
||||
// JWT
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.9" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.8" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.32.0" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.32.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user