5

My goal is to provide a code snippet to customers. One file will contain customer's business logic, another file will provide its handling. For the latter I need to have a name of a function [would like to avoid asking customers to enter this information manually].

I searched around but could not figure out. Essentially I need this:

enter image description here

1 Answer 1

16

The ExecutionContext class has a property FunctionName (docs)

You can inject the class like this:

[FunctionName("HttpTriggered")]
public IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]
     HttpRequest req, 
     ExecutionContext executionContext)
{
     var name = executionContext.FunctionName;
     ...
}

The output will be

HttpTriggered

Update 11-2025

For isolated runtime functions things are more complicated and you need the FunctionContext class and use FunctionDefinition.Name. See the docs. However, this class cannot be used using DI, see this issue. But, a workaround is presented in that same issue.

Sign up to request clarification or add additional context in comments.

5 Comments

Hi @Peter Bons , Does this work? I'm unable to 'FunctionName' from executionContext. Please clarify!! Thanks.
@DeepakShaw I see that for isolated functions you'll need another class, see the updated answer
Hi @Pater Bons, Thanks for updating your answer, however, when I inject the FunctionContext though Function Constructor, I'm getting this error: "System.InvalidOperationException: Unable to resolve service for type 'Microsoft.Azure.Functions.Worker.FunctionContext' while attempting to activate".
@DeepakShaw My bad, seems for isolated functions DI cannot be used. See the updated answer for a possible workaround
@Pater Bons, Yes it worked just a little modification var fnName = functionContext.FunctionDefinition.Name;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.