-
-
Save stevetalkscode/8f2e6c7b7284e380621aa03b3b253a57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public delegate string GetSkuDelegate(); | |
public interface IDateTimeWrapper | |
{ | |
DateTime GetCurrentDateTimeUtc(); | |
} | |
public interface IProductFactory | |
{ | |
Product Create(string productName); | |
} | |
public class DateTimeWrapper : IDateTimeWrapper | |
{ | |
public DateTime GetCurrentDateTimeUtc() => DateTime.UtcNow; | |
} | |
public class UserAccessor | |
{ | |
private readonly IHttpContextAccessor _ctx; | |
public UserAccessor(IHttpContextAccessor ctx) | |
{ | |
_ctx = ctx; | |
} | |
public IUser GetUser() | |
{ | |
var userName = _ctx.HttpContext.User.Identity?.Name; | |
var userIdValue = _ctx.HttpContext.User.Claims.FirstOrDefault(c => c.Subject?.Name == "UserId")?.Value ?? string.Empty; | |
var userId = int.Parse(userIdValue); | |
return new User(userId, userName); | |
} | |
private record User(int UserId, string Name) : IUser; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment