Class PartyService
Service for managing party entities in the database. Provides async operations for party creation, deletion, and retrieval. Implements execution strategies for automatic retry on transient database failures. Returns DatabaseResult for consistent, safe error handling.
public sealed class PartyService : BaseService<PartyEntity>, IPartyService, IExistsByKeyAction<long>, IDeleteByKeyAction<long>
- Inheritance
-
PartyService
- Implements
- Inherited Members
Remarks
This service manages party lifecycle including:
- Party creation with generated IDs
- Party deletion with CASCADE cleanup of memberships and update records
- Party existence checks and retrieval
Database operations are executed via the BaseService execution wrappers for:
- Automatic transient failure retry
- Centralized exception handling and mapping
- Consistent DatabaseResult pattern
Party membership is managed separately by CharacterPartyService. Party updates are tracked by PartyUpdateService.
Constructors
PartyService(INpgsqlDbContextFactory)
Initializes a new instance of PartyService.
public PartyService(INpgsqlDbContextFactory dbContextFactory)
Parameters
dbContextFactoryINpgsqlDbContextFactoryDbContext factory for creating contexts.
Exceptions
- ArgumentNullException
Thrown when dbContextFactory is null.
Methods
CreateAsync(long, CancellationToken)
Creates a new party and returns the generated party ID.
public Task<DatabaseResult<long>> CreateAsync(long worldServerId, CancellationToken cancellationToken = default)
Parameters
worldServerIdlongWorld server the party will belong to.
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
- Task<DatabaseResult<long>>
A DatabaseResult<T> containing the new party ID on success.
Remarks
Parties are independent entities that do not belong to a specific account. Characters join parties through the party membership relationship.
A party belongs to one world server. Characters are global and may be played on any of them, but a party is replicated between scene servers through this database within a single world server's pump — so a party whose members were spread across two would be updated by pumps that cannot see one another and would never converge. Recording the world server here is what lets a membership be dropped when a character arrives somewhere it cannot work.
DeleteAsync(long, CancellationToken)
Deletes the entity identified by the given key.
public Task<DatabaseResult> DeleteAsync(long partyId, CancellationToken cancellationToken = default)
Parameters
partyIdlongcancellationTokenCancellationTokenToken to cancel the operation.
Returns
Remarks
Atomicity:
This operation uses a single DELETE statement. CASCADE delete constraints automatically remove related data:
- All character party memberships (character_party table)
- Party update notifications (party_update table)
ExistsAsync(long, CancellationToken)
Checks whether an entity exists for the given key.
public Task<DatabaseResult<bool>> ExistsAsync(long partyId, CancellationToken cancellationToken = default)
Parameters
partyIdlongcancellationTokenCancellationTokenToken to cancel the operation.
Returns
FetchAsync(long, CancellationToken)
Fetches a party by its ID.
public Task<DatabaseResult<PartyData?>> FetchAsync(long partyId, CancellationToken cancellationToken = default)
Parameters
partyIdlongThe party ID.
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
- Task<DatabaseResult<PartyData?>>
A DatabaseResult<T> containing the party data if found, or null if the party does not exist.