Skip to main content
Namespace: Numa.Services
Related Models: User.cs
Related Interfaces: IUserService.cs

Fields

Field NameTypeDescription
_dbContextFactoryIDbContextFactory<NumaContext>DbContextFactory for instantiating instances of NumaContext on-demand
_authenticationStateProviderAuthenticationStateProviderProvider for authentication state, registered in Program.cs

Constructor

public UserService( IDbContextFactory<NumaContext> dbContextFactory, AuthenticationStateProvider authenticationStateProvider )
{
    _dbContextFactory = dbContextFactory ?? throw new ArgumentNullException( nameof( dbContextFactory ) );
    _authenticationStateProvider = authenticationStateProvider ?? throw new ArgumentNullException( nameof( authenticationStateProvider ) );
}

Properties

Property NameTypeDescription
CurrentUserUser?Object to represent the state of the current user

Methods

Method NameDescriptionParametersReturn Type
InitializeCurrentUserAsyncInitializes the value of CurrentUserTask
GetOrCreateUserAsyncGets or creates a new User from a ClaimsPrincipalClaimsPrincipalTask<User>

IUserService.cs

using Numa.Models;
using System.Security.Claims;

namespace Numa.Interfaces
{
    public interface IUserService
    {
        User? CurrentUser { get; }
        Task InitializeCurrentUserAsync();
        Task<User> GetOrCreateUserAsync( ClaimsPrincipal principal );
    }
}