Extend UsingEfCoreSqlServer to be able to influence DbContextOptionsBuilder
ngruson opened this issue · comments
My database is running in Azure SQL and my application is deployed to Azure Container Apps.
The container app is configured with a managed identity.
To connect to the database using the managed identity, I use a DbConnectionInterceptor
implementation as described here: https://stackoverflow.com/questions/54187241/ef-core-connection-to-azure-sql-with-managed-identity.
I'd like to extend the UsingEfCoreSqlServer
method from SetupExtensions.cs
.
I'd like to pass in an optional action parameter to be able to call AddInterceptors
on the DbContextOptionsBuilder
.
Action<DbContextOptionsBuilder>? configureDbContextOptions = null
In the app setup, I then can do:
.UsingEfCoreSqlServer(
myConnectionString,
builder => builder.AddInterceptors(new AzureAuthenticationInterceptor())
)
Do you agree with this or should I have another approach to connect to SQL with a managed identity?
Hi @ngruson,
The AuthP library has a custom database feature, which allows you to control the creation of the DbContext - see Setup the custom database feature.
However I think there is a simpler approach - you copy the UsingEfCoreSqlServer
code from the AuthPermissions/SetupExtensions
class and add your Interceptor. See this section from my "Using custom databases with the AuthP library – Part1: normal apps" article which has a nice diagram.
Yep agreed, I can run my own extension method.