Search code examples
azure.net-corecoding-styleazure-functions

Best practices for writing/organising azure functions in project/solution


I have multiple azure functions created. Some are related a similar functionality and others different. Let say: 1. File Movement - TimerTrigger 2. Processing - HttpTrigger

For File Movement I have 2 functions and for Processing say another 2 functions. I have created 4 azure functions in the same project. Is it the right way?

  1. Should I put FileMovement functions in same class file and Processing in different class file - same project/solution?
  2. Separate project for all azure functions?

Applications settings value must be shared across all the azure functions.


Solution

  • I've blogged about this a while ago.

    I suggest the following:

    • For larger solutions: Apply Domain Driven Design principles to your solution. Keep the functions which require to work together (within a bounded context, or a module within a bounded context) within one Function App. "What changes together should be deployed together."

    • Check the scaling requirements of the individual functions. If all functions have the same scaling behavior then they can stay in the same Function App. If some functions require different scaling than others, keep them in seperate Function App.

    • Personally, I like to have one function definition per class since that allows me to use nameof(FunctionClass) in the FunctionName attribute, as I descibed in this post.

    • Use solution folders to keep the code in the Function App structured. One of my demo projects on GitHub: DurableFunctions.Demo.DotNetCore.