I have a FunctionApp running that exposes some entities and they all have the same CRUD operations that follow the same pattern and I was wondering if there was a way I could generalize this in the code. But I'm struggling a bit since everything is declared using attributes and they need to reference constants and those cannot be overridden in a derived class.
I would ideally like to have a base class like this, however I face the problem with the constants.
public abstract class EntityFunctions<T>
{
protected const string someConstant = "Derived?";
protected const string someOtherConstant = "Derived?";
protected readonly ICrudService<T> _crudService;
public EntityFunctions(ICrudService<T> crudService){
_crudService = crudService;
}
[FunctionName("Create" + someConstant)]
public async Task<string> Create([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = someOtherConstant)] T request)
{
return _crudService.Create(request);
}
}
public class MyEntityFunctions : EntityFunctions<MyEntity>{
...
}
Is there a way around this? Some other way to ensure unique function-names and define "base"-routes. Or can functions be registered in another manner?