0

What I have

I have an ASP.NET Core 5.0 Blazor Server app used for internal management, in includes Services which are also used in my actual product app.

I have a dev and staging db with identical schemas.

I have services where I inject my DbContext (which load my staging or dev connection string depending on the environment), in the typical fashion.

What I need:

I want my management page to show content from both my dev and staging db.

I think something like this is what I need:

Create a DbContext for Staging and Dev, eg StagingDbContext and DevDbContext

For each service e.g. ICarService, keep my implementation CarService but now create 2 implementations like DevCarService and StagingCarService which inherit? CarService so that it can:

Pass the relevant DbContext

Be injected where I need (my management.razor page can inject DevCarService and StagingCarService).

I hope that was clear.

Thank you

slaw
  • 611
  • 2
  • 7
  • 20
  • 1
    You miss which IoC Container do you use, I suppose Microsoft.DependencyInjection. You can create two class `class StagingDbContext : YourDbContext` and class DevDbContext : YourDbContext` and add its to the container with different connection string. For the implementation of ICarService, you can create two class `DevCarService` and `ProdCarService` inherit from CarService and add to the IoC. Otherwise you can create a [service locator](https://stackoverflow.com/questions/39174989/how-to-register-multiple-implementations-of-the-same-interface-in-asp-net-core) – Max Oct 20 '21 at 10:40
  • correct me if I am wrong, what you want is two implementation for every interface (dev, staging) in your app rather than two separate deployments ? – Hoshani Oct 20 '21 at 13:15

0 Answers0