diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppHub.Chatbot.cs b/src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppHub.Chatbot.cs index a464b270d4..dfee99d860 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppHub.Chatbot.cs +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppHub.Chatbot.cs @@ -20,7 +20,9 @@ public partial class AppHub public async IAsyncEnumerable Chatbot( StartChatbotRequest request, IAsyncEnumerable incomingMessages, - [EnumeratorCancellation] CancellationToken cancellationToken) + [EnumeratorCancellation] CancellationToken cancellationToken, + [FromServices] AppDbContext dbContext, + [FromServices] IChatClient chatClient) { // Incoming user messages are received via `incomingMessages`. // We utilize `Channel` to read incoming messages and send responses using `ChatClient`. @@ -37,10 +39,6 @@ public async IAsyncEnumerable Chatbot( culture = CultureInfo.GetCultureInfo(request.CultureId); } - await using var scope = serviceProvider.CreateAsyncScope(); - - var dbContext = scope.ServiceProvider.GetRequiredService(); - supportSystemPrompt = (await dbContext .SystemPrompts.FirstOrDefaultAsync(p => p.PromptKind == PromptKind.Support, cancellationToken))?.Markdown ?? throw new ResourceNotFoundException(); @@ -55,7 +53,6 @@ public async IAsyncEnumerable Chatbot( } Channel channel = Channel.CreateUnbounded(new() { SingleReader = true, SingleWriter = true }); - var chatClient = serviceProvider.CreateAsyncScope().ServiceProvider.GetRequiredService(); async Task ReadIncomingMessages() { diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppHub.cs b/src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppHub.cs index a0a2d1a06e..9f2a396954 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppHub.cs +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppHub.cs @@ -48,6 +48,7 @@ public override async Task OnDisconnectedAsync(Exception? exception) /// /// While SignalR client is connected, the user might sign-in or sign-out. /// In this case, we need to update the authentication state of the SignalR connection. + /// This method is called by AppClientCoordinator.cs /// public Task ChangeAuthenticationState(string? accessToken) { @@ -67,11 +68,8 @@ public Task ChangeAuthenticationState(string? accessToken) /// /// [Authorize(Policy = AppFeatures.System.ManageLogs)] - public async Task GetUserSessionLogs(Guid userSessionId) + public async Task GetUserSessionLogs(Guid userSessionId, [FromServices] AppDbContext dbContext) { - await using var scope = serviceProvider.CreateAsyncScope(); - var dbContext = scope.ServiceProvider.GetRequiredService(); - var userSessionSignalRConnectionId = await dbContext.UserSessions .Where(us => us.Id == userSessionId) .Select(us => us.SignalRConnectionId)