Class LoginServerService
Login server registration and management service. Uses EF Core compiled queries for hot paths and the BaseService execution strategy for retries.
public sealed class LoginServerService : BaseService<LoginServerEntity>, ILoginServerService, IFetchByKeyAction<long, LoginServerData>
- Inheritance
-
LoginServerService
- Implements
- Inherited Members
Constructors
LoginServerService(INpgsqlDbContextFactory)
Initializes a new instance of LoginServerService.
public LoginServerService(INpgsqlDbContextFactory dbContextFactory)
Parameters
dbContextFactoryINpgsqlDbContextFactoryDbContext factory for creating contexts.
Exceptions
- ArgumentNullException
Thrown when dbContextFactory is null.
Methods
DeleteAsync(long, CancellationToken)
Deletes a login server registration.
public Task<DatabaseResult> DeleteAsync(long serverId, CancellationToken cancellationToken = default)
Parameters
serverIdlongServer ID to delete. Must be greater than 0.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<DatabaseResult>
DatabaseResult indicating success or failure with error details.
Remarks
Success: Server registration removed from database. If the server does not exist, this operation still succeeds. Failure cases:
- VALIDATION_ERROR: Invalid server ID (less than or equal to 0)
- DATABASE_ERROR: Unexpected database error
FetchAsync(long, CancellationToken)
Fetches an entity for the given key.
public Task<DatabaseResult<LoginServerData>> FetchAsync(long serverId, CancellationToken cancellationToken = default)
Parameters
serverIdlongcancellationTokenCancellationTokenToken to cancel the operation.
Returns
PersistAsync(string, string, ushort, CancellationToken)
Adds or updates a login server registration.
public Task<DatabaseResult<LoginServerData>> PersistAsync(string name, string address, ushort port, CancellationToken cancellationToken = default)
Parameters
namestringServer name (unique identifier). Must not be null or whitespace.
addressstringServer address. Must not be null or whitespace.
portushortServer port.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<DatabaseResult<LoginServerData>>
DatabaseResult containing LoginServerData with server ID and details on success.
Remarks
Success: Returns complete server data including generated ID. Failure cases:
- VALIDATION_ERROR: Invalid name or address (null/whitespace)
- UNIQUE_VIOLATION: A unique constraint was violated (non-transient). Note: normal concurrent registration by name is handled via UPSERT and should not produce this.
- DATABASE_ERROR: Unexpected database error
PulseAsync(long, CancellationToken)
Updates the last pulse timestamp for a login server (heartbeat).
public Task<DatabaseResult> PulseAsync(long serverId, CancellationToken cancellationToken = default)
Parameters
serverIdlongServer ID. Must be greater than 0.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<DatabaseResult>
DatabaseResult indicating success or failure with error details.
Remarks
Success: Pulse timestamp updated. Failure cases:
- VALIDATION_ERROR: Invalid server ID (less than or equal to 0)
- ENTITY_NOT_FOUND: Server does not exist
- DATABASE_ERROR: Unexpected database error