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
databasePathstringThe path to the SQLite database file.
Properties
DatabasePath
Gets the database file path.
public string DatabasePath { get; }
Property Value
Default
Gets or sets the default SQLite identity storage instance.
public static SqliteIdentityStorage Default { get; set; }
Property Value
IsDefaultInit
Gets a value indicating whether the default storage has been initialized.
public static bool IsDefaultInit { get; }
Property Value
Methods
AddToRoleAsync(string, string, CancellationToken)
Adds a user to a role asynchronously.
public Task AddToRoleAsync(string userId, string normalizedRoleName, CancellationToken cancellationToken)
Parameters
userIdstringThe user ID.
normalizedRoleNamestringThe normalized role name.
cancellationTokenCancellationTokenThe cancellation token.
Returns
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
roleTRoleThe role to create.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<IdentityResult>
The result of the operation.
Type Parameters
TRoleThe 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
userTUserThe user to create.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<IdentityResult>
The result of the operation.
Type Parameters
TUserThe 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
roleTRoleThe role to delete.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<IdentityResult>
The result of the operation.
Type Parameters
TRoleThe 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
userTUserThe user to delete.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<IdentityResult>
The result of the operation.
Type Parameters
TUserThe 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
disposingboolTrue 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
roleIdstringThe role ID.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TRole>
The role if found, otherwise null.
Type Parameters
TRoleThe 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
normalizedNamestringThe normalized role name.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TRole>
The role if found, otherwise null.
Type Parameters
TRoleThe 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
normalizedEmailstringThe normalized email address.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TUser>
The user if found, otherwise null.
Type Parameters
TUserThe 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
userIdstringThe user ID.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TUser>
The user if found, otherwise null.
Type Parameters
TUserThe 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
normalizedUserNamestringThe normalized user name.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TUser>
The user if found, otherwise null.
Type Parameters
TUserThe 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
userIdstringThe user ID.
cancellationTokenCancellationTokenThe cancellation token.
Returns
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
TRoleThe 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
normalizedRoleNamestringThe normalized role name.
cancellationTokenCancellationTokenThe cancellation token.
Returns
Type Parameters
TUserThe 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
TUserThe 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
userIdstringThe user ID.
normalizedRoleNamestringThe normalized role name.
cancellationTokenCancellationTokenThe cancellation token.
Returns
RemoveFromRoleAsync(string, string, CancellationToken)
Removes a user from a role asynchronously.
public Task RemoveFromRoleAsync(string userId, string normalizedRoleName, CancellationToken cancellationToken)
Parameters
userIdstringThe user ID.
normalizedRoleNamestringThe normalized role name.
cancellationTokenCancellationTokenThe cancellation token.
Returns
UpdateRoleAsync<TRole>(TRole, CancellationToken)
Updates an existing role asynchronously.
public Task<IdentityResult> UpdateRoleAsync<TRole>(TRole role, CancellationToken cancellationToken) where TRole : SqliteIdentityRole
Parameters
roleTRoleThe role to update.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<IdentityResult>
The result of the operation.
Type Parameters
TRoleThe 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
userTUserThe user to update.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<IdentityResult>
The result of the operation.
Type Parameters
TUserThe type of user to update.