Table of Contents

Class SqliteIdentityStorage

Namespace
Hi.SqliteUtils
Assembly
HiNc.dll

SQLite-based storage for ASP.NET Core Identity.

public class SqliteIdentityStorage : IDisposable
Inheritance
SqliteIdentityStorage
Implements
Inherited Members
Extension Methods

Constructors

SqliteIdentityStorage(string)

Initializes a new instance of the SqliteIdentityStorage class.

public SqliteIdentityStorage(string databasePath = null)

Parameters

databasePath string

The path to the SQLite database file.

Properties

DatabasePath

Gets the database file path.

public string DatabasePath { get; }

Property Value

string

Default

Gets or sets the default SQLite identity storage instance.

public static SqliteIdentityStorage Default { get; set; }

Property Value

SqliteIdentityStorage

IsDefaultInit

Gets a value indicating whether the default storage has been initialized.

public static bool IsDefaultInit { get; }

Property Value

bool

Methods

AddToRoleAsync(string, string, CancellationToken)

Adds a user to a role asynchronously.

public Task AddToRoleAsync(string userId, string normalizedRoleName, CancellationToken cancellationToken)

Parameters

userId string

The user ID.

normalizedRoleName string

The normalized role name.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

ClearAllData()

Clears all identity data (users, roles, and user-role associations).

public void ClearAllData()

CreateRoleAsync<TRole>(TRole, CancellationToken)

Creates a new role asynchronously.

public Task<IdentityResult> CreateRoleAsync<TRole>(TRole role, CancellationToken cancellationToken) where TRole : SqliteIdentityRole

Parameters

role TRole

The role to create.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IdentityResult>

The result of the operation.

Type Parameters

TRole

The type of role to create.

CreateUserAsync<TUser>(TUser, CancellationToken)

Creates a new user asynchronously.

public Task<IdentityResult> CreateUserAsync<TUser>(TUser user, CancellationToken cancellationToken) where TUser : SqliteIdentityUser

Parameters

user TUser

The user to create.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IdentityResult>

The result of the operation.

Type Parameters

TUser

The type of user to create.

DeleteRoleAsync<TRole>(TRole, CancellationToken)

Deletes a role asynchronously.

public Task<IdentityResult> DeleteRoleAsync<TRole>(TRole role, CancellationToken cancellationToken) where TRole : SqliteIdentityRole

Parameters

role TRole

The role to delete.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IdentityResult>

The result of the operation.

Type Parameters

TRole

The type of role to delete.

DeleteUserAsync<TUser>(TUser, CancellationToken)

Deletes a user asynchronously.

public Task<IdentityResult> DeleteUserAsync<TUser>(TUser user, CancellationToken cancellationToken) where TUser : SqliteIdentityUser

Parameters

user TUser

The user to delete.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IdentityResult>

The result of the operation.

Type Parameters

TUser

The type of user to delete.

Dispose()

Releases all resources used by the SqliteIdentityStorage.

public void Dispose()

Dispose(bool)

Releases the unmanaged resources used by the SqliteIdentityStorage and optionally releases the managed resources.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

True to release both managed and unmanaged resources; false to release only unmanaged resources.

FindRoleByIdAsync<TRole>(string, CancellationToken)

Finds a role by its ID asynchronously.

public Task<TRole> FindRoleByIdAsync<TRole>(string roleId, CancellationToken cancellationToken) where TRole : SqliteIdentityRole, new()

Parameters

roleId string

The role ID.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TRole>

The role if found, otherwise null.

Type Parameters

TRole

The type of role to find.

FindRoleByNameAsync<TRole>(string, CancellationToken)

Finds a role by its normalized name asynchronously.

public Task<TRole> FindRoleByNameAsync<TRole>(string normalizedName, CancellationToken cancellationToken) where TRole : SqliteIdentityRole, new()

Parameters

normalizedName string

The normalized role name.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TRole>

The role if found, otherwise null.

Type Parameters

TRole

The type of role to find.

FindUserByEmailAsync<TUser>(string, CancellationToken)

Finds a user by their normalized email asynchronously.

public Task<TUser> FindUserByEmailAsync<TUser>(string normalizedEmail, CancellationToken cancellationToken) where TUser : SqliteIdentityUser, new()

Parameters

normalizedEmail string

The normalized email address.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TUser>

The user if found, otherwise null.

Type Parameters

TUser

The type of user to find.

FindUserByIdAsync<TUser>(string, CancellationToken)

Finds a user by their ID asynchronously.

public Task<TUser> FindUserByIdAsync<TUser>(string userId, CancellationToken cancellationToken) where TUser : SqliteIdentityUser, new()

Parameters

userId string

The user ID.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TUser>

The user if found, otherwise null.

Type Parameters

TUser

The type of user to find.

FindUserByNameAsync<TUser>(string, CancellationToken)

Finds a user by their normalized user name asynchronously.

public Task<TUser> FindUserByNameAsync<TUser>(string normalizedUserName, CancellationToken cancellationToken) where TUser : SqliteIdentityUser, new()

Parameters

normalizedUserName string

The normalized user name.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TUser>

The user if found, otherwise null.

Type Parameters

TUser

The type of user to find.

GetRolesAsync(string, CancellationToken)

Gets the roles for a user asynchronously.

public Task<IList<string>> GetRolesAsync(string userId, CancellationToken cancellationToken)

Parameters

userId string

The user ID.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IList<string>>

A list of role names.

GetRoles<TRole>()

Gets all roles as a queryable collection.

public IQueryable<TRole> GetRoles<TRole>() where TRole : SqliteIdentityRole, new()

Returns

IQueryable<TRole>

A queryable collection of roles.

Type Parameters

TRole

The type of roles to retrieve.

GetUsersInRoleAsync<TUser>(string, CancellationToken)

Gets all users in a role asynchronously.

public Task<IList<TUser>> GetUsersInRoleAsync<TUser>(string normalizedRoleName, CancellationToken cancellationToken) where TUser : SqliteIdentityUser, new()

Parameters

normalizedRoleName string

The normalized role name.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IList<TUser>>

A list of users in the role.

Type Parameters

TUser

The type of users to retrieve.

GetUsers<TUser>()

Gets all users as a queryable collection.

public IQueryable<TUser> GetUsers<TUser>() where TUser : SqliteIdentityUser, new()

Returns

IQueryable<TUser>

A queryable collection of users.

Type Parameters

TUser

The type of users to retrieve.

IsInRoleAsync(string, string, CancellationToken)

Checks if a user is in a role asynchronously.

public Task<bool> IsInRoleAsync(string userId, string normalizedRoleName, CancellationToken cancellationToken)

Parameters

userId string

The user ID.

normalizedRoleName string

The normalized role name.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<bool>

True if the user is in the role, otherwise false.

RemoveFromRoleAsync(string, string, CancellationToken)

Removes a user from a role asynchronously.

public Task RemoveFromRoleAsync(string userId, string normalizedRoleName, CancellationToken cancellationToken)

Parameters

userId string

The user ID.

normalizedRoleName string

The normalized role name.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

UpdateRoleAsync<TRole>(TRole, CancellationToken)

Updates an existing role asynchronously.

public Task<IdentityResult> UpdateRoleAsync<TRole>(TRole role, CancellationToken cancellationToken) where TRole : SqliteIdentityRole

Parameters

role TRole

The role to update.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IdentityResult>

The result of the operation.

Type Parameters

TRole

The type of role to update.

UpdateUserAsync<TUser>(TUser, CancellationToken)

Updates an existing user asynchronously.

public Task<IdentityResult> UpdateUserAsync<TUser>(TUser user, CancellationToken cancellationToken) where TUser : SqliteIdentityUser

Parameters

user TUser

The user to update.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IdentityResult>

The result of the operation.

Type Parameters

TUser

The type of user to update.