1

I have an existing ASP.Net Core Web API and now I want to create the admin module as a separate ASP.Net Core application but sharing the same database.

My problem now is how to handle my DBContext in the new solution especially because of the the following line containing the ApplicationUser model

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>

and also the other model classes which exist in the existing solution from where I need to create my DBSet entitie sets to enable me query the database.

I wish to have the admin module to be a completely separate application hosted on a different domain/server but having access to the same database so that the admin can manage the database table entries from the admin solution.

I don't want it to be a separate project on the same solution. Rather I want it to be a completely separate solution/application which can be hosted independently.

I will appreciate any guide to achieving this if it is possible with ASP.Net Core.

I am using ASP.Net Core 5 with Entity Framework Core but I can migrate to version 6 if that offers a solution.

3
  • I would start by completely separating ApplicationDbContext and IdentityDbContext. But we can only give opinions and suggestions here. Commented Jan 16, 2022 at 18:54
  • @GertArnold your opinion and suggestions are highly welcome. Please go ahead and explain how to go about it Commented Jan 16, 2022 at 20:22
  • No, Stack Overflow is not the right platform. Commented Jan 16, 2022 at 20:44

2 Answers 2

1

You need to create a model as a separate (third) project, build a nuget of that Model project and include it in both. There are some small challenges, since you are going to run migrations on this standalone project - but nothing that cannot be overcome

It's very straightforward (and possible since ASP.NET Core 1).

Sign up to request clarification or add additional context in comments.

10 Comments

Can the models be a class library instead of a nugget? Or could you explain more why it has to be a nugget
First, it's nuget, not nugget. Second - and more important, it is class library. nuget is the easier way to package class library, and include in other projects. But if you want more pain - sure, you can just fight unpackaged DLLs
Thank you. I will give it a shot and revert
Do you mean that the DBContext and the models would be the make-up of the 3rd standalone application?
@Josh - yes, exactly
|
0

You can have multiple contexts for single database. It can be useful for example if your database contains multiple database schemas and you want to handle each of them as separate self contained area.

Read the link below

https://www.tutorialspoint.com/entity_framework/entity_framework_multiple_dbcontext.htm

1 Comment

This has nothing to do with original question - but hey, it may help somebody else

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.