Identityserver4 在启动外部访问ConfigurationDbContext
在startup.cs中配置ConfigurationDbContext后,如何在startup类外部访问该实例?Identityserver4 在启动外部访问ConfigurationDbContext,identityserver4,Identityserver4,在startup.cs中配置ConfigurationDbContext后,如何在startup类外部访问该实例? 我想用ConfigurationDbContext创建一个存储库,并想使用与启动中配置的ConfigurationDbContext相同的实例。正如您在IdentityServer4.EntityFramework中所看到的那样,ConfigurationDbContext在内置DI中注册为作用域(实际上是指“每个web请求”)。此外,它还注册为IConfigurationDbCo
我想用ConfigurationDbContext创建一个存储库,并想使用与启动中配置的ConfigurationDbContext相同的实例。正如您在
IdentityServer4.EntityFramework
中所看到的那样,ConfigurationDbContext
在内置DI中注册为作用域
(实际上是指“每个web请求”)。此外,它还注册为IConfigurationDbContext
接口的实现
要访问ConfigurationDbContext
实例,只需通过DI将其注入您的服务中:
公共MyService(IConfigurationDbContext)
{
}
公共HomeController(ConfigurationDbContext上下文)
{
}