I am wondering if there is an easy way to determine the implementation of an interface by layer in ASP.NET Core.
For example, take this diagram

- Let's say both DataAccess.Customer and DataAccess.Employee both depend on IMySqlConnection in their repositories.
- But both layers require different connection configuration options or implementations
Is there an easy way to have the Application Layer automatically inject different IMySqlConnections for all potential DataAccess.Customer and DataAccess.Employee repositories?
Or would there be a better way to handle this?
Thanks!
If you are using or can upgrade to .NET 8 you can use freshly introduced feature allowing keyed services registration. For example:
And in DAL:
For pre .NET 8 you can create some kind of factory which will accept corresponding settings (for example, or this).