0

I have a separate database for every client. I want to initialize EF Core context using dependency injection at function app startup. How can I achieve this?

I want to avoid initializing a connection for the same database on every function call when the function app is already running.

9
  • Pass the connection string in a constructor. See here. Commented May 3, 2020 at 18:44
  • @GertArnold I have a single function app and a growling list of database per client i.e. each client has a separate database but the schema of every database is the same. The referenced approach seems suitable only if there is one database. Commented May 4, 2020 at 6:54
  • Did you read the accepted answer? Commented May 4, 2020 at 7:25
  • @tehmas have you referred to markheath.net/post/ef-core-di-azure-functions? Commented May 4, 2020 at 7:42
  • @JimXu I had referred to Jeff's article for injecting context of the database which has the tenant profiles of all the tenants e.g. the db name, server etc. of a particular tenant. When a function is triggered, say by a queue message, it contains the tenant name to specify whose message is this. I'm using the injected dependency to get the db credentials to establish a connection with the desired db. I want to improve the second step. Establishing a connection multiple times from a set of multiple dbs is an overhead. dev.to/azure/using-entity-framework-with-azure-functions-50aa Commented May 5, 2020 at 4:58

0

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.