Search code examples
c#azurewindows-serviceswebjob

Ways to leverage single code base between Windows Service and Azure WebJob


I'm working on a timed recurring process that in some cases will be deployed OnPrem and in other cases deployed in the cloud (Azure). I'm researching a Windows Service and an Azure WebJob. Given that I only need the recurring process to be the timed piece, I'm thinking about having the bulk of the logic in a library with just the entry points being different between the Windows Service for the local deployment or a WebJob when deploying to Azure. Each csproj (service and WebJob) would handle only the timed loop and configuration settings then call into the library for the bulk of the work.

My question is: Is there another design combination available to me that would fulfill these requirements potentially in a better way? I've read about wrapping an existing windows service in a WebJob, but I don't think that would be necessary in this case given I'm starting from scratch.


Solution

  • When it comes to keeping your common code up to date, and knowing which versions are used by which applications, bets solution is to create a class library project with respected design pattern and convert it into a nuget project.

    you know you can host your own private NuGet repository, create your own packages, and host them internally within your own network.

    enter image description here

    Here is a very nice article for"How to create Nuget package out of your class library project". You can utilize it and share it across all your code.

    And finally you can just callit from your windows service/WebJob.

    Let me know if you need any help related to designing the solution.

    Hope it helps.