MentorAgent Docs
Menu

ReferencePackage: Novior.MentorAgent.Server

MentorHubScopes class

The MentorHubScopes class of Novior.MentorAgent.Server.Hubs: Keeps ONE DI scope per SignalR connection, so the MentorAgent coordinator (MCP connections…

View as Markdown
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.

Namespace: Novior.MentorAgent.Server.Hubs. Package: Novior.MentorAgent.Server.

public sealed class MentorHubScopes : IAsyncDisposable

Terminal
dotnet add package Novior.MentorAgent.Server

public MentorHubScopes(IServiceScopeFactory scopeFactory)

public ValueTask DisposeAsync()

public IServiceProvider GetOrCreate(string connectionId)

Returns the service provider of this connection's scope, creating it on first use.

public ValueTask RemoveAsync(string connectionId)

Disposes this connection's scope (closes MCP connections, disposes the orchestrator).

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.