VS2022 template "ASP.NET Core Worker Service template" missing

EuroEager2008 171 Reputation points
2023-05-19T09:36:38.71+00:00

The article
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?source=recommendations&view=aspnetcore-7.0&tabs=visual-studio
mentions a template named "ASP.NET Core Worker Service template".

I assume this is ment to be a template accesible by VS2022, but I cannot find it.
What am I doing wrong?

Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other
A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.
{count} votes

Answer accepted by question author
  1. Anonymous
    2023-05-19T12:27:05.77+00:00

    Hi @EuroEager2008 ,

    I didn't find a template to run worker service in asp.net core app/API project officially. But there are some clues to do this. Although the article uses Ihost to build service project. You can still register the service class directly to asp.net core project which host by webapplicationbuilder like below.

    builder.Services.AddHostedService<TimedHostedService>();
    builder.Services.AddHostedService<Worker>();
    
    

    (Note that the 'worker' is copy from the default worker service template," TimedHostedService" is the code from https://learn.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?source=recommendations&view=aspnetcore-7.0&tabs=visual-studio#timed-background-tasks ).

    They will work the same as in a Ihostbuilder project.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.