コード例 #1
0
        private static void ConfigureRequestsAccountInjection(IServiceCollection services)
        {
            services.AddTransient <IHttpContextAccessor, HttpContextAccessor>();

            services.AddTransient((serviceProvider) =>
            {
                IHttpContextAccessor httpContextAccessor = serviceProvider.GetService <IHttpContextAccessor>();

                ClaimsPrincipal user = httpContextAccessor.HttpContext.User;

                string accountIdValue = user.FindFirstValue(JwtClaimIdentifiers.Id);
                string email          = user.FindFirstValue(ClaimTypes.NameIdentifier);

                long.TryParse(accountIdValue, out long accountId);

                var accountLite = new AccountLite
                {
                    Id    = accountId,
                    Email = email
                };

                return(accountLite);
            });
        }
コード例 #2
0
 public AccountController(IAccountsService accountsService, AccountLite account)
 {
     _accountsService = accountsService;
     _account         = account;
 }