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