Skip to content

Commit

Permalink
Update AiClientStartupValidationBackgroundService and version
Browse files Browse the repository at this point in the history
Updated AiClientStartupValidationBackgroundService to use IServiceScopeFactory for creating a new scope, allowing access to IAiClient service inside ExecuteAsync method. A null check is also added for serviceScopeFactory. This change accommodates scenarios where AiClient may be required in the background service. Also, incremented the project version to 4.0.2-alpha in the Directory.Build.props file to reflect latest changes and maintain proper versioning.
  • Loading branch information
rodion-m committed Dec 5, 2023
1 parent f77e387 commit fa9c23c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>4.0.1-alpha</Version>
<Version>4.0.2-alpha</Version>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace OpenAI.ChatGpt.AspNetCore;

internal class AiClientStartupValidationBackgroundService : BackgroundService
{
private readonly IServiceScopeFactory _serviceScopeFactory;

public AiClientStartupValidationBackgroundService(AiClientFromConfiguration _)
public AiClientStartupValidationBackgroundService(IServiceScopeFactory serviceScopeFactory)
{
_serviceScopeFactory = serviceScopeFactory ?? throw new ArgumentNullException(nameof(serviceScopeFactory));
}

protected override Task ExecuteAsync(CancellationToken stoppingToken) => Task.CompletedTask;
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await using var scope = _serviceScopeFactory.CreateAsyncScope();
_ = scope.ServiceProvider.GetRequiredService<IAiClient>();
}
}

0 comments on commit fa9c23c

Please sign in to comment.