File tree Expand file tree Collapse file tree
src/Services/Marketing/Marketing.API Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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 ( ) ;
You can’t perform that action at this time.
0 commit comments