Fix IoC
This commit is contained in:
@@ -6,6 +6,7 @@ using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Infrastructure;
|
||||
using skydiveLogs_api.Infrastructure.Interfaces;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace skydiveLogs_api.Ioc
|
||||
{
|
||||
@@ -38,7 +39,7 @@ namespace skydiveLogs_api.Ioc
|
||||
|
||||
_services.AddSingleton<ICacheService, CacheService>();
|
||||
_services.AddScoped<IIdentityService, IdentityService>();
|
||||
_services.AddScoped(s => s.GetService<IHttpContextAccessor>()?.HttpContext.User);
|
||||
_services.AddScoped<ClaimsPrincipal>(s => s.GetService<IHttpContextAccessor>()?.HttpContext.User);
|
||||
|
||||
_services.AddScoped<IAircraftRepository, AircraftRepository>();
|
||||
_services.AddScoped<IDropZoneRepository, DropZoneRepository>();
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
|
||||
using AutoMapper;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using skydiveLogs_api.DataContract;
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DataContract;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Controllers
|
||||
{
|
||||
public class AircraftController : Base
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public AircraftController(IAircraftService aircraftService,
|
||||
IMapper mapper)
|
||||
{
|
||||
@@ -20,6 +19,18 @@ namespace skydiveLogs_api.Controllers
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
// DELETE: api/ApiWithActions/5
|
||||
[HttpDelete("{id}")]
|
||||
[EnableCors]
|
||||
public void Delete(int id)
|
||||
{
|
||||
_aircraftService.DeleteAircraftById(id);
|
||||
}
|
||||
|
||||
// GET: api/Aircraft
|
||||
[HttpGet]
|
||||
[EnableCors]
|
||||
@@ -54,15 +65,13 @@ namespace skydiveLogs_api.Controllers
|
||||
_aircraftService.UpdateAircraft(id, _mapper.Map<Aircraft>(value));
|
||||
}
|
||||
|
||||
// DELETE: api/ApiWithActions/5
|
||||
[HttpDelete("{id}")]
|
||||
[EnableCors]
|
||||
public void Delete(int id)
|
||||
{
|
||||
_aircraftService.DeleteAircraftById(id);
|
||||
}
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IAircraftService _aircraftService;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,23 +7,5 @@ namespace skydiveLogs_api.Controllers
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
||||
public class Base : ControllerBase
|
||||
{
|
||||
//public User ConnectedUser
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// if (_connectedUser == null)
|
||||
// {
|
||||
// _connectedUser = new User();
|
||||
// _connectedUser.Login = User.Claims.Single(c => c.Type == ClaimTypes.Name).Value;
|
||||
// _connectedUser.Id = Convert.ToInt32(User.Claims.Single(c => c.Type == ClaimTypes.UserData).Value);
|
||||
// }
|
||||
|
||||
// return _connectedUser;
|
||||
// }
|
||||
//}
|
||||
|
||||
//private User _connectedUser;
|
||||
}
|
||||
public class Base : ControllerBase { }
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
|
||||
using AutoMapper;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using skydiveLogs_api.DataContract;
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DataContract;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Controllers
|
||||
{
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
|
||||
using AutoMapper;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using skydiveLogs_api.DataContract;
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DataContract;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Controllers
|
||||
{
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
|
||||
using AutoMapper;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using skydiveLogs_api.DataContract;
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DataContract;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Controllers
|
||||
{
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
|
||||
using AutoMapper;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using skydiveLogs_api.DataContract;
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DataContract;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Controllers
|
||||
{
|
||||
public class JumpTypeController : Base
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public JumpTypeController(IJumpTypeService jumpTypeService,
|
||||
IMapper mapper)
|
||||
{
|
||||
@@ -20,6 +19,18 @@ namespace skydiveLogs_api.Controllers
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
// DELETE: api/ApiWithActions/5
|
||||
[HttpDelete("{id}")]
|
||||
[EnableCors]
|
||||
public void Delete(int id)
|
||||
{
|
||||
_jumpTypeService.DeleteJumpTypeById(id);
|
||||
}
|
||||
|
||||
// GET: api/JumpType
|
||||
[HttpGet]
|
||||
[EnableCors]
|
||||
@@ -54,15 +65,13 @@ namespace skydiveLogs_api.Controllers
|
||||
_jumpTypeService.UpdateJumpType(id, _mapper.Map<JumpType>(value));
|
||||
}
|
||||
|
||||
// DELETE: api/ApiWithActions/5
|
||||
[HttpDelete("{id}")]
|
||||
[EnableCors]
|
||||
public void Delete(int id)
|
||||
{
|
||||
_jumpTypeService.DeleteJumpTypeById(id);
|
||||
}
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IJumpTypeService _jumpTypeService;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,17 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
using AutoMapper;
|
||||
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using skydiveLogs_api.DataContract;
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DataContract;
|
||||
using skydiveLogs_api.Settings;
|
||||
|
||||
using System;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
|
||||
namespace skydiveLogs_api.Controllers
|
||||
{
|
||||
@@ -22,6 +19,8 @@ namespace skydiveLogs_api.Controllers
|
||||
[ApiController]
|
||||
public class UserController : Base
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public UserController(IUserService userService,
|
||||
IMapper mapper,
|
||||
IOptions<JwtSettings> jwtSettings)
|
||||
@@ -31,6 +30,10 @@ namespace skydiveLogs_api.Controllers
|
||||
_jwtConf = jwtSettings.Value;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
// GET: api/User/AlwayLogin
|
||||
[HttpGet("AlwaysLogin")]
|
||||
[EnableCors]
|
||||
@@ -39,7 +42,6 @@ namespace skydiveLogs_api.Controllers
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
// POST: api/User/Authenticate
|
||||
[AllowAnonymous]
|
||||
[HttpPost("Authenticate")]
|
||||
@@ -90,6 +92,8 @@ namespace skydiveLogs_api.Controllers
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
// PUT: api/User/5
|
||||
//[HttpPut("{id}")]
|
||||
//[EnableCors]
|
||||
@@ -98,6 +102,8 @@ namespace skydiveLogs_api.Controllers
|
||||
// _userService.UpdateUser(id, _mapper.Map<User>(value));
|
||||
//}
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private string CreateToken(UserResp foundUser)
|
||||
{
|
||||
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_jwtConf.Passphrase));
|
||||
@@ -118,8 +124,14 @@ namespace skydiveLogs_api.Controllers
|
||||
return new JwtSecurityTokenHandler().WriteToken(token);
|
||||
}
|
||||
|
||||
private readonly IUserService _userService;
|
||||
private readonly IMapper _mapper;
|
||||
#endregion Private Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly JwtSettings _jwtConf;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IUserService _userService;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,15 @@
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.Ioc;
|
||||
using skydiveLogs_api.Settings;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace skydiveLogs_api
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user