MentorHubScopes class
The MentorHubScopes class of Novior.MentorAgent.Server.Hubs: Keeps ONE DI scope per SignalR connection, so the MentorAgent coordinator (MCP connections…
On this page
Keeps ONE DI scope per SignalR connection, so the MentorAgent coordinator (MCP connections, skills, discovery, agent) is built once per connection and reused for every message — mirroring Blazor Server's "one scope per circuit" model. Without this, SignalR's default "one scope per hub method call" would, on every message: - rebuild the coordinator and reconnect the external MCP servers (spawning a process each time), - and start a brand-new AgentSession, so the conversation history never persisted. Singleton. Each connection's scope is disposed when the connection ends.
Definition
Section titled “Definition”Namespace: Novior.MentorAgent.Server.Hubs. Package: Novior.MentorAgent.Server.
public sealed class MentorHubScopes : IAsyncDisposable
dotnet add package Novior.MentorAgent.ServerConstructors
Section titled “Constructors”public MentorHubScopes(IServiceScopeFactory scopeFactory)
Methods
Section titled “Methods”DisposeAsync
Section titled “DisposeAsync”public ValueTask DisposeAsync()
GetOrCreate
Section titled “GetOrCreate”public IServiceProvider GetOrCreate(string connectionId)
Returns the service provider of this connection's scope, creating it on first use.
RemoveAsync
Section titled “RemoveAsync”public ValueTask RemoveAsync(string connectionId)
Disposes this connection's scope (closes MCP connections, disposes the orchestrator).
TryGet
Section titled “TryGet”public IServiceProvider? TryGet(string connectionId)
Returns an existing connection scope without creating one, or null. Used by out-of-band HTTP endpoints (e.g. POST /mentor/cancel) that must reach the live orchestrator of a SignalR connection without going through the hub — a hub method cannot run while SendMessage is awaiting on the same connection.
