Class LeaderboardService
Default ILeaderboardService implementation. Delegates persistence and querying to an injected ILeaderboardStore, ranks results via LeaderboardRanker, and broadcasts submission/clear signals through an optional event dispatcher.
Inherited Members
Namespace: Serenity.Leaderboard.Application.Services
Assembly: Serenity.Leaderboard.Application.dll
Syntax
public class LeaderboardService : ILeaderboardService, IService, IFoundationSettings
Remarks
Unknown boards never throw: they log a warning and return an empty/no-op result, matching the framework's never-throw-in-runtime philosophy.
Constructors
LeaderboardService(ILeaderboardStore, IReadOnlyDictionary<BoardId, LeaderboardDefinition>, IEventDispatcherService, ILogService)
Initializes a new instance of the LeaderboardService class.
Declaration
public LeaderboardService(ILeaderboardStore store, IReadOnlyDictionary<BoardId, LeaderboardDefinition> boards, IEventDispatcherService eventDispatcherService, ILogService logService)
Parameters
| Type | Name | Description |
|---|---|---|
| ILeaderboardStore | store | Backend store used to persist and query leaderboard entries. |
| IReadOnlyDictionary<BoardId, LeaderboardDefinition> | boards | Registered leaderboard definitions, keyed by their board identifier. |
| IEventDispatcherService | eventDispatcherService | Dispatcher used to broadcast LeaderboardEntrySubmittedSignal and
LeaderboardClearedSignal. May be |
| ILogService | logService | Logging service. May be |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
Properties
Guid
Declaration
public string Guid { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Id
Declaration
public string Id { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
LogService
Declaration
public ILogService LogService { get; set; }
Property Value
| Type | Description |
|---|---|
| ILogService |
Methods
ClearAsync(BoardId, CancellationToken)
Clears every entry from a board.
Declaration
public virtual Task ClearAsync(BoardId board, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| BoardId | board | The board to clear. |
| CancellationToken | cancellationToken | Token used to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task |
GetAroundPlayerAsync(BoardId, PlayerId, int, CancellationToken)
Gets the entries surrounding a player's position on a board.
Declaration
public virtual Task<LeaderboardPage> GetAroundPlayerAsync(BoardId board, PlayerId player, int radius, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| BoardId | board | The board to query. |
| PlayerId | player | The player to center the window on. |
| int | radius | The number of entries to include on each side of the player. |
| CancellationToken | cancellationToken | Token used to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<LeaderboardPage> | A page containing the windowed entries. |
GetPlayerRankAsync(BoardId, PlayerId, CancellationToken)
Gets a player's ranked entry on a board.
Declaration
public virtual Task<RankedEntry?> GetPlayerRankAsync(BoardId board, PlayerId player, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| BoardId | board | The board to query. |
| PlayerId | player | The player to look up. |
| CancellationToken | cancellationToken | Token used to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<RankedEntry?> | The player's ranked entry, or null when the player has no entry on the board. |
GetTopAsync(BoardId, int, LeaderboardRankingMode, CancellationToken)
Gets the top-ranked entries for a board.
Declaration
public virtual Task<LeaderboardPage> GetTopAsync(BoardId board, int count, LeaderboardRankingMode rankingMode, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| BoardId | board | The board to query. |
| int | count | The maximum number of entries to return. |
| LeaderboardRankingMode | rankingMode | BestPerPlayer collapses the result to one row per player, ranked by their best entry (matches the three-argument overload). AllEntries returns every stored row as its own ranked entry — a player may occupy more than one rank. |
| CancellationToken | cancellationToken | Token used to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<LeaderboardPage> | A page containing the top-ranked entries. |
GetTopAsync(BoardId, int, CancellationToken)
Gets the top-ranked entries for a board, ranked over each player's best entry.
Declaration
public virtual Task<LeaderboardPage> GetTopAsync(BoardId board, int count, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| BoardId | board | The board to query. |
| int | count | The maximum number of entries to return. |
| CancellationToken | cancellationToken | Token used to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<LeaderboardPage> | A page containing the top-ranked entries. |
SubmitAsync(LeaderboardSubmission, CancellationToken)
Submits a score to the leaderboard identified by the submission's board.
Declaration
public virtual Task SubmitAsync(LeaderboardSubmission submission, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| LeaderboardSubmission | submission | The submission data. |
| CancellationToken | cancellationToken | Token used to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task |