Skip to content

Commit

Permalink
feat: Start services concurrently
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Jan 28, 2024
1 parent 7cd037d commit 614bac3
Show file tree
Hide file tree
Showing 3 changed files with 21 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,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.17.0.82934">
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.18.0.83559">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
4 changes: 1 addition & 3 deletions src/LinkDotNet.Blog.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ private static void RegisterServices(WebApplicationBuilder builder)
builder.Services.AddBlazoredToast();
builder.Services.RegisterServices();
builder.Services.AddStorageProvider(builder.Configuration);
builder.Services.AddResponseCompression();
builder.Services.AddHostedService<BlogPostPublisher>();
builder.Services.AddHostedService<TransformBlogPostRecordsService>();
builder.Services.AddBackgroundServices();

builder.Services.AddHealthChecks()
.AddCheck<DatabaseHealthCheck>("Database");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using LinkDotNet.Blog.Web.Features;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace LinkDotNet.Blog.Web.RegistrationExtensions;

public static class BackgroundServiceRegistrationExtensions
{
public static void AddBackgroundServices(this IServiceCollection services)
{
services.Configure<HostOptions>(options =>
{
options.ServicesStartConcurrently = true;
options.ServicesStopConcurrently = true;
});
services.AddHostedService<BlogPostPublisher>();
services.AddHostedService<TransformBlogPostRecordsService>();
}
}

0 comments on commit 614bac3

Please sign in to comment.