Skip to content

Commit

Permalink
Update the Worker template to use Host.CreateApplicationBuilder (do…
Browse files Browse the repository at this point in the history
…tnet#47720)

* Update the Worker template to use  `Host.CreateApplicationBuilder`

The callback approach that `Host.CreateDefaultBuilder` uses is no longer recommended going forward, and the programming model is no longer used in ASP.NET apps - it uses the `WebApplication.CreateBuilder()` API which is imperative, top-to-bottom programming. The Worker template should follow the same pattern.

Fix dotnet#43113

* Use var to fit in with ASP.NET.
  • Loading branch information
eerhardt authored Apr 20, 2023
1 parent 03e670f commit 816b2ea
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ public class Program
{
public static void Main(string[] args)
{
IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddHostedService<Worker>();
})
.Build();
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddHostedService<Worker>();

var host = builder.Build();
host.Run();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using Company.Application1;

IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddHostedService<Worker>();
})
.Build();
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddHostedService<Worker>();

var host = builder.Build();
host.Run();
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ open Microsoft.Extensions.DependencyInjection
open Microsoft.Extensions.Hosting

module Program =
let createHostBuilder args =
Host.CreateDefaultBuilder(args)
.ConfigureServices(fun hostContext services ->
services.AddHostedService<Worker>() |> ignore)

[<EntryPoint>]
let main args =
createHostBuilder(args).Build().Run()
let builder = Host.CreateApplicationBuilder(args)
builder.Services.AddHostedService<Worker>() |> ignore

builder.Build().Run()

0 // exit code

0 comments on commit 816b2ea

Please sign in to comment.