Skip to content

Instantly share code, notes, and snippets.

@stevetalkscode
Created October 18, 2020 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevetalkscode/8f2e6c7b7284e380621aa03b3b253a57 to your computer and use it in GitHub Desktop.
Save stevetalkscode/8f2e6c7b7284e380621aa03b3b253a57 to your computer and use it in GitHub Desktop.
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