Skip to content

Use of Primary constructor stating that they are private readonly #39740

@Krighaar

Description

@Krighaar

Type of issue

Missing information

Description

In the section https://learn.microsoft.com/en-us/dotnet/core/extensions/windows-service#rewrite-the-worker-class

the code shown, is using Primary constructor. In the description it states that:

Both are made available to the class as private readonly

a) This is not what the code is showing.
b) Primary constructors are not private readonly.

It should state that we are using primary constructors, and/or adding an example on how to assign them to private readonly fields like so:

public sealed class WindowsBackgroundService(
    JokeService JokeService,
    ILogger<WindowsBackgroundService> logger) : BackgroundService
{
    
    private readonly Jokeservice jokeService { get; } = JokeService;
    
    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
...

Page URL

https://learn.microsoft.com/en-us/dotnet/core/extensions/windows-service

Content source URL

https://github.com/dotnet/docs/blob/main/docs/core/extensions/windows-service.md

Document Version Independent Id

64d5cdf8-e50f-0c89-7f16-82645ba6383e

Article author

@IEvangelist

Metadata

  • ID: ed148088-4550-2788-0756-390eab15e3f6
  • Service: dotnet-fundamentals

Associated WorkItem - 217544

Metadata

Metadata

Assignees

Labels

📌 seQUESTeredIdentifies that an issue has been imported into Quest.dotnet-fundamentals/svcokr-qualityContent-quality KR: Concerns article defects (bugs), freshness, or build warnings.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions