How to publish environment specific appsettings in .Net core app?

If someone else is wondering how to use different appsettings for multiple environments here is a possible solution. dotnet publish –configuration [Debug|Release] will copy the appropriate appsettings.json file into the publish folder if *.csproj has a conditional logic for these files: First in the .pubxml publish profile file (can be found in Properties->PublishProfiles of Visual … Read more

How to register multiple implementations of the same interface in Asp.Net Core?

I did a simple workaround using Func when I found myself in this situation. Firstly declare a shared delegate: public delegate IService ServiceResolver(string key); Then in your Startup.cs, setup the multiple concrete registrations and a manual mapping of those types: services.AddTransient<ServiceA>(); services.AddTransient<ServiceB>(); services.AddTransient<ServiceC>(); services.AddTransient<ServiceResolver>(serviceProvider => key => { switch (key) { case “A”: return serviceProvider.GetService<ServiceA>(); … Read more