Base solution for your next web application
Open Closed

Injecting Azure KeyVault in WebCoreModule as dependency to fetch SQL Azure Connection string #11290


User avatar
0
zdeen created

Hi , We are using this version of ASPNET ZERO:

ASP.NET CORE & Angular .NET Core 2.2 v7.2.3

The application is hosted in Azure and the datastore used is SQL Azure. Connection string is in appsetting file and is fetched via _appConfiguration.GetConnectionString.

I was trying to move this to Azure KeyVault so that API code can fetch SQL Server connection string from Azure KeyVault.So was trying to inject Azure KeyVault in WebCoreModule as dependency to fetch SQL Azure Connection string

I have written an implementation on top of Azure KeyVault called KeyVaultManager in my code which connects to KeyVault and fetch the details . When I tried injecting it to WebCoreModule this is the exception it throws:

*HandlerException: Can't create component 'OneSense.Web.OneSenseWebCoreModule' as it has dependencies to be satisfied.

'OneSense.Web.OneSenseWebCoreModule' is waiting for the following dependencies:

  • Service 'OneSense.Core.Platform.KeyVault.IKeyVaultManager' which was not registered. Castle.MicroKernel.Handlers.DefaultHandler.AssertNotWaitingForDependency()

HandlerException: Can't create component 'OneSense.Web.OneSenseWebCoreModule' as it has dependencies to be satisfied. 'OneSense.Web.OneSenseWebCoreModule' is waiting for the following dependencies: - Service 'OneSense.Core.Platform.KeyVault.IKeyVaultManager' which was not registered.*

Is there a way where this dependency can be injected in constructor of OneSenseWebCoreModule along with IHostingEnvironment. This is the first secret application needs to fetch from KeyVault and was thinking if there is a better way of doing this.

Please let me know if there is any other details which is needed from my side.


2 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @zdeen

    Dependency Injection initialization happens in module classes, so you can't use dependency injection in module constructor.

    You can use ;

    var keyVaultManager = Abp.Dependency.IocManager.Instance.Resolve<IKeyVaultManager>();

  • User Avatar
    0
    zdeen created

    Thanks @ismcagdas .This really helped,