Skip to content

A sample project demonstrating running a Vazor web application under Kestrel in a TopShelf service

License

Notifications You must be signed in to change notification settings

CommunityVB/VazorTopShelf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VazorTopShelf

This sample demonstrates running a Vazor VB.NET Web application under Kestrel, hosted in a Windows Service using TopShelf.

It started as a simple .NET Core VB.NET Console application. The Project SDK value was updated from Microsoft.NET.Sdk to Microsoft.NET.Sdk.Web and the Vazor and TopShelf packages were added. Essential files were copied from a new Vazor-template-sourced project. Service-related classes were then moved to a separate ServiceRunner project, for improved separation of concerns.

To install the service, dotnet publish to your desired output directory, and then run the following command from an elevated command prompt in that directory:

VazorTopShelf.exe install

This will install the service. You can then start it using net start VazorTopShelf or services.msc. With the service running, navigate to http://localhost:5000/ to view the application and access its pages. At service start, a simple SQLite database will automatically be created in a new Db\Data folder alongside wwwroot (if they don't exist already).

The installation is configured in the Host.Run() method to set the service's startup type to Automatic (Delayed Start). You can change this setting to your liking by calling HostConfig.Disabled(), HostConfig.StartManually(), HostConfig.StartAutomatically() or HostConfig.StartAutomaticallyDelayed().

To uninstall the service, run the following command from an elevated command prompt:

VazorTopShelf.exe uninstall

Here's a high-level view of how it works:

  1. The Program module is the entry point for the application. It initializes a Host instance, and then calls the Host.Run() method.
  2. Host.Run() sets the stage for the service, including specifying what happens when the service starts and stops.
  3. The Manager.StartService() method configures and invokes the constructor-provided OnStart() action—which in turn configures and starts the website—when the service starts. Note that the WebApplication class provides a Run() method, which blocks and listens on a port and which we normally use, but since TopShelf handles the blocking all we need here is the listening component, StartAsync().

Notes

Current date: Jan 27, 2024

About

A sample project demonstrating running a Vazor web application under Kestrel in a TopShelf service

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published