Should I create separate package to host web api as windows service in .net core 3.1?

Ashutosh Arun Pareek 76 Reputation points
2021-03-22T12:00:05.777+00:00

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?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,156 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,251 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,231 questions
0 comments No comments
{count} votes

Accepted answer
  1. Duane Arnold 3,211 Reputation points
    2021-03-22T20:52:42.07+00:00

    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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful