0

We have a Blazor Server-Aapp. The app uses ef core. After authorization / login i want to change the database connection for the current session. I have some ideas but does anybody knows the best aproach for this? We do not use a repository. The context is just directly injected where it is needed.

  • Does this answer your question? [How can I connect to multiple databases from a Blazor .NET Core project?](https://stackoverflow.com/questions/62100637/how-can-i-connect-to-multiple-databases-from-a-blazor-net-core-project) – agua from mars Jul 31 '20 at 16:58
  • Is it just for 2 databases or full multi-tennant? – H H Jul 31 '20 at 17:03
  • its for multi-tennant - sorry that describes exact what i want. – Ralf Meeh Jul 31 '20 at 17:21

1 Answers1

0

I assume you want to use different databases for login and other data entities. In that case, why not create different DbContext one for auth purpose and other for data entities?

One DbContext can have connection string for auth database and the other for your business data. For example:

Auth data context:

services.AddDbContext<AuthContext>(options =>
    options.UseSqlServer(Configuration.GetConnectionString("AuthConnection")));

Business data context:

services.AddDbContext<DataContext>(options =>
    options.UseSqlServer(Configuration.GetConnectionString("DataConnection")));
Umair
  • 4,864
  • 3
  • 28
  • 47
  • The op clearly says: After authorization / login i want to change the database connection for the current session. Injection occurs before this. – Brian Parker Jul 31 '20 at 20:36