aboutsummaryrefslogtreecommitdiff
path: root/ExamTemplate/Data/ExamTemplate.Data/TemplateContextFactory.cs
blob: 8b2c0fafae9ccf0a6d09534188edb037ac9b9a8b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using System.IO;

namespace ExamTemplate.Data
{
	public class TemplateContextFactory : IDesignTimeDbContextFactory<TemplateContext>
	{
		public TemplateContext CreateDbContext(string[] args)
		{
			var configuration = new ConfigurationBuilder()
				.SetBasePath(Directory.GetCurrentDirectory() + "/../../Web/CarShop.Web/")
				.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
				.AddJsonFile("appsettings.Development.json", optional: true)
				.Build();

			var optionsBuilder = new DbContextOptionsBuilder<TemplateContext>()
				.UseNpgsql(configuration.GetConnectionString("LocalDBConnection"));

			return new TemplateContext(optionsBuilder.Options);
		}
	}
}