question

AshutoshArunPareek-8484 avatar image
0 Votes"
AshutoshArunPareek-8484 asked ·

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?

dotnet-csharpdotnet-aspnet-generaldotnet-aspnet-core-generaldotnet-aspnet-core-mvcdotnet-aspnet-core-webapi
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DuaneArnold-0443 avatar image
1 Vote"
DuaneArnold-0443 answered ·

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.

· 3 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Agree, so do you recommend two different packages?
first one will be .App
and second one act as wrapper over first one with just one modification .UseWindowsService named App.Windows

0 Votes 0 ·
miwan2-msft avatar image miwan2-msft AshutoshArunPareek-8484 ·

I suggest you could spilt your library into smaller code units and independent of OS.

1 Vote 1 ·
DuaneArnold-0443 avatar image DuaneArnold-0443 AshutoshArunPareek-8484 ·

Sounds reasonable but I have never faced the situation.

0 Votes 0 ·