2.0 KiB
IUserService
File:
src/EchoHub.Core/Contracts/IUserService.cs
Kind: interface
public interface IUserService
IUserService is the asynchronous contract for common user-account operations: registration, authentication, and profile access. Implementations may back these calls with REST, an IRC gateway, or other transports, but callers interact with this interface to perform login, account creation, and profile queries without coupling to a specific transport.
Remarks
By returning Task<UserOperationResult> for mutating operations and Task<UserProfileDto?> for profile queries, the interface cleanly models success/failure and optional data. The UserOperationResult type provides Success(UserProfileDto user) and Fail(UserError error, string message) helpers, enabling implementations to construct consistent outcomes. The RegisterUserAsync method carries a server-policies cue in its comment: when Server:Registration = "invite", an inviteCode is required; in "closed" mode, new accounts are refused. This centralizes registration policy at the service boundary and avoids scattering policy checks across call sites.
Example
// Example usage of IUserService
public async Task DemoAsync(IUserService userService)
{
var reg = await userService.RegisterUserAsync("alice", "Secret123", inviteCode: "INVITE-42");
if (reg.IsSuccess)
{
var profile = await userService.GetUserProfileAsync("alice");
// Use profile as needed
}
}
Notes
- The
inviteCodeparameter is context-sensitive and should be supplied when the server is configured withServer:Registration = "invite"; otherwise it may be omitted. - All methods are asynchronous; callers should
awaitthe results and branch onUserOperationResult.IsSuccessas appropriate. GetUserProfileAsyncandGetUserByIdAsyncreturnUserProfileDto?, reflecting the possibility that a user profile may not be found or accessible in certain contexts.