Open jez9999 opened 1 year ago
Tagging subscribers to this area: @dotnet/area-extensions-hosting See info in area-owners.md if you want to be subscribed.
Author: | jez9999 |
---|---|
Assignees: | - |
Labels: | `api-suggestion`, `untriaged`, `area-Extensions-Hosting` |
Milestone: | - |
You could use something like
using Microsoft.Extensions.Hosting.Systemd;
using Microsoft.Extensions.Hosting.WindowsServices;
public static bool IsRunAsService { get; } = IsRunAsServiceCore();
private static bool IsRunAsServiceCore()
{
return WindowsServiceHelpers.IsWindowsService()
|| SystemdHelpers .IsSystemdService();
}
Does this fit your needs?
Background and motivation
The
.UseWindowsService()
and.UseSystemd()
extensions allow a host builder to be configured to run as a Windows or systemd service if it's detected that they're currently running in one of those contexts, but it'd be useful for the program to actually know whether that activation happened. They should therefore be able to report back as to whether they detected that the current program was running as a Windows or systemd service, and therefore activated.API Proposal
API Usage
Alternative Designs
No response
Risks
No response