-
Notifications
You must be signed in to change notification settings - Fork 722
Expand file tree
/
Copy pathDynamicDbContextFactory.cs
More file actions
33 lines (25 loc) · 948 Bytes
/
DynamicDbContextFactory.cs
File metadata and controls
33 lines (25 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using Microsoft.EntityFrameworkCore;
using System.Data.Entity.Infrastructure;
using System.Data.Entity;
using TodoApi.Services;
namespace TodoApi.Models
{
public class DynamicDbContextFactory
{
private readonly ITenantService _tenantService;
public DynamicDbContextFactory(ITenantService tenantService)
{
_tenantService = tenantService;
}
public TodoContext CreateDbContext()
{
var connectionString = _tenantService.GetConnectionString();
var optionsBuilder = new DbContextOptionsBuilder<TodoContext>();
//TODO: here need to set the connection string for the database
//optionsBuilder.UseSqlServer(connectionString);
//optionsBuilder.UseSqlite(connectionString);
optionsBuilder.UseInMemoryDatabase(connectionString);
return new TodoContext(optionsBuilder.Options);
}
}
}