Azure / Azure/azure-functions-dotnet-extensions

Dependency injection based on trigger parameter

Open
#20 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
81
Forks
50
PR merge metrics
No merged PRs in 30d

Description

My function is part of a multi-tenant solution so it needs to connect to multiple databases based on the Message headers from Even Bus. So in order to inject a proper `Repository` class I need to get the `tenant id` from the message. Is there a way to resolve a dependence by accessing a `Message` before function execution.

Here's a sample to visualize the problem :

```
[FunctionName("DonationEventFunction")]
public async static void Run(
[ServiceBusTrigger("topic", "subscription", Connection = "EventBusConn")] Message message,
ILogger log,
IConfiguration configuration,

**IRepository repo**
)
{
// ideally I'd like to have IRepository injected in FunctionsStartup however that is not possible as I need to get tenant id from message.

// this is what I have to do now .... but this makes DI impossible
var tenantId = message.GetTenantId();
var repo = new SqlRepoImplementation(tenantId).
}
```

So I am looking to see if there's a way to access `message` and inject the `repo` before function is executed.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the Run entry point and the FunctionsStartup, ServiceBusTrigger, Message, and IRepository elements shown in the issue. Determine whether dependency resolution can use the message before function execution, and document the supported approach or limitation with a clear tenant-aware repository outcome.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
backend, cloud
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.