I am trying to make a base/abstract class that contains an Azure Function, which I can use from within a different project when it inherits from the base, but can't seem to get the functions from within the base class of the first project to appear.
(Currently using Azure Functions v3 in .Net Core 3.1 in VS2019)
Here's what I have tried...
Base class in project 1:
public class BaseClass
{
[FunctionName("Function1")]
public IActionResult Function1(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
ILogger log)
{
// Function 1 code in here
}
}
New class in project 2:
public class NewClass : BaseClass
{
[FunctionName("Function2")]
public IActionResult Function2(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
ILogger log)
{
// Function 2 code in here
}
}
So, when I run project 2 locally, I thought I should get Function1 and Function2 endpoints ready to be used, but I only get the endpoint for Function2 that is available.
If I run project 1 locally, I get the endpoint for Function 1.
Is this even possible in Azure Functions and, if so, how do I achieve this?
UPDATE - If I move the BaseClass from project 1 into project 2, I get what I want, namely Function 1 and Function 2 at the same time.
UPDATE 2 Repro steps:
- Create project 1: Create a new Azure Functions v3 targeting .Net 3.1.
- Add an Azure Function using an HTTP trigger.
- Run the project. (Basic/demo function 1 should run as expected.)
- Create project 2: add another new project in the same solution: Azure Functions v3 targeting .Net 3.1.
- Add an Azure Function using an HTTP trigger (to the new project).
- Run the new project. (Basic/demo function 2 should run as expected.)
- Add a project reference from Project 2 to Project 1.
- Make Project 2's class inherit from Project 1's class.
- Change each function in each project to NOT be a static class (to allow inheritance to work)
- Run Project 2 - only Project 2's functions are displayed.
...then...
Move the Function1.cs file from Project 1 into Project 2 and rename classes/namespaces appropriately and then run the project... both functions are displayed.