1

Looking to understand if this is possible. If so, then how? If not, then why?

I would like to have a single azure queue function process messages like this:

{
  "tenanatDb": Db_Name_3102,
  "command": "getCountryCurrencies",
  "args": "US"
}

I'm using DI so in my Function I have a Startup

internal class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services.AddDbContext<MyDbContext>(options =>
            options
                .UseSqlServer("<ConnectionString>"));

            builder.Services.AddSingleton<IMyService>((s) => {
                return new MyService();
            });
        }
    }

I can provide a connection string, however, what can I do so that a standard connection string is used, but the Database is specified at runtime from the Queue Message:

Server=myServerAddress;Database=***Db_Name_3102***;User Id=myUsername;Password=myPassword;

Thanks

I have been able to get this working in this way, however, it does not use Dependency Injection.

SomeClass obj = new SomeClass("DatabaseName");
obj.getCoutnryCurrecies(args);

In the SomeClass constructor, I'm setting up the database connection string.

  • See https://stackoverflow.com/questions/67445703/ef-core-to-call-database-based-on-parameter-in-api/67449401#67449401 But I don't know if there's something similar to the HttpContextAccessor that will give you access to the message details. I suspect not. – David Browne - Microsoft Nov 03 '22 at 19:23

0 Answers0