Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DevComm] Example doesn't compile #50694

@gewarren

Description

@gewarren

The following example:

using DependencyInjection.Example;

HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);

builder.Services.AddHostedService();
builder.Services.AddSingleton<IMessageWriter, MessageWriter>();

using IHost host = builder.Build();

host.Run();

However does not compile or run as the method Host.CreateApplicationBuilder(args); The correct method is without args.

Furthermore, the package Microsoft.Extensions.Hosting is not referenced. This package must be added and referenced.

As a programmer with in excess of 40 years experience I find these sort of errors astounding and inconceivable through lack of validating and checking to ensure accuracy and completeness in a written piece of work. Especially, when that work is written to teach a subject.

Try following the steps and see if the example compiles when considering absolute no prior knowledge of this subject. I guarantee that step cannot be done successfully.

Page URL

https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection

Content source URL

https://github.com/dotnet/docs/blob/main/docs/core/extensions/dependency-injection.md

Document Version Independent Id

cc5f00d0-fb50-1229-8fa2-e66b1f45b284

Platform Id

7f5b5732-fc3e-6ffb-b8b8-77b5659a8015

Article author

@IEvangelist

Metadata

  • ID: 8fd55089-b683-2202-6641-c7b61a132f14
  • PlatformId: 7f5b5732-fc3e-6ffb-b8b8-77b5659a8015
  • Service: dotnet-fundamentals

Related Issues

Metadata

Metadata

Assignees

Type

No type

Projects

Status

🔖 Ready

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions