IMHO, just because you're using .NET Core, it doesn't mean that that you don't distinguish and separate code that can run on two different platforms.
Should I create separate package to host web api as windows service in .net core 3.1?
Some background :
I have common Web API library which adds Serilogger and Splunk integration/implementation for ILogger along with handling of common services/Middlewares such as Custom Authentication/Authorization, Exception Handling, Request/Response logging(For auditing) and many other feature in terms of extension methods for ease of development. This library is used by multiple teams for their Web API development.
My Question:
Library right now assumes that everything is hosted on Kestrel but recenlty some teams started hosting web api in Windows Service(Purpose can't be disclosed:)) and IIS as well.
Right now my Program.cs (All the custom code for Serilog and Splunk is removed) :
Host.CreateDefaultBuilder(args)
ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
}).Build().Run();
I am planning to take -ws
in args
to decide if I should host it as Windows Service or not.
If -ws is present in args then my code will look as following:
Host.CreateDefaultBuilder(args)
.UseWindowsService()
...
But doing above will also result in having windows based binaries in the linux deployable folders as well. So should I create two different packages for my purpose or what I am doing here is Ok?