Skip to content

Commit 699ec00

Browse files
committed
Create IdentityService in marketing API
1 parent b28c650 commit 699ec00

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Services
7+
{
8+
public interface IIdentityService
9+
{
10+
string GetUserIdentity();
11+
}
12+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Microsoft.AspNetCore.Http;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
7+
namespace Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Services
8+
{
9+
public class IdentityService : IIdentityService
10+
{
11+
private IHttpContextAccessor _context;
12+
13+
public IdentityService(IHttpContextAccessor context)
14+
{
15+
_context = context ?? throw new ArgumentNullException(nameof(context));
16+
}
17+
18+
public string GetUserIdentity()
19+
{
20+
return _context.HttpContext.User.FindFirst("sub").Value;
21+
}
22+
}
23+
}

src/Services/Marketing/Marketing.API/Startup.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
namespace Microsoft.eShopOnContainers.Services.Marketing.API
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Services;
3+
4+
namespace Microsoft.eShopOnContainers.Services.Marketing.API
25
{
36
using Microsoft.AspNetCore.Builder;
47
using Microsoft.AspNetCore.Hosting;
@@ -110,6 +113,8 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
110113
});
111114

112115
services.AddTransient<IMarketingDataRepository, MarketingDataRepository>();
116+
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
117+
services.AddTransient<IIdentityService, IdentityService>();
113118

114119
//configure autofac
115120
var container = new ContainerBuilder();

0 commit comments

Comments
 (0)