Refactor scope creation and update namespace imports

Replaced `IServiceProvider` with `IServiceScopeFactory` for async scope creation, updated injected services and usages, switched namespace import from `System.Text.RegularExpressions` to `Microsoft.Extensions.AI`, and simplified the `FormatTokenUsageDetails` method signature to use the unqualified `UsageDetails` type.
This commit is contained in:
Marco Minerva
2026-07-24 17:32:08 +02:00
parent 7af4214d6d
commit 6c3e539272
@@ -1,7 +1,7 @@
@page "/ask"
@using System.Text.RegularExpressions
@using Microsoft.Extensions.AI
@inject IServiceProvider ServiceProvider
@inject IServiceScopeFactory ServiceScopeFactory
@inject IJSRuntime JSRuntime
<PageTitle>Chat with your data</PageTitle>
@@ -176,7 +176,7 @@
try
{
await using var scope = ServiceProvider.CreateAsyncScope();
await using var scope = ServiceScopeFactory.CreateAsyncScope();
var vectorSearchService = scope.ServiceProvider.GetRequiredService<VectorSearchService>();
var response = vectorSearchService.AskStreamingAsync(userQuestion);
@@ -260,7 +260,7 @@
return $"{reformulation}{question}";
static string FormatTokenUsageDetails(Microsoft.Extensions.AI.UsageDetails? tokenUsage)
static string FormatTokenUsageDetails(UsageDetails? tokenUsage)
{
if (tokenUsage is null)
{