Search code examples
c#apiarchitecturebackend

C# API and Data Access Layer connection strings


I have a question regarding connection strings and where they should be stored. Should connection strings be initialized in my API (startup.cs) before calling the manager layer or do I create another configuration file that runs a (startup.cs) within my data access layer. I've read the tutorials on Microsoft's API tutorial but there i'm not understanding where to initially store my connection strings.


Solution

  • For C#, in your DAL API, store them in your app settings file and inject them into your DAL classes through dependency injection in startup.cs. This is great for local development.

    For production, you can then swop that out for secrets stored in Azure Key Vault, by adding a few lines to your host builder wire up.

    This link should help:

    https://learn.microsoft.com/en-us/azure/azure-app-configuration/use-key-vault-references-dotnet-core?tabs=core5x