This repository has been archived on 2024-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
NG_2023_Kanban/NG_2023_Kanban.DataLayer/DbStartup/Injecting.cs

36 lines
1.3 KiB
C#
Raw Normal View History

2023-05-16 22:09:57 +03:00
using NG_2023_Kanban.DataLayer.Service;
2023-05-17 12:36:49 +03:00
using NG_2023_Kanban.DataLayer.Repositories;
using NG_2023_Kanban.DataLayer.Interfaces;
2023-05-11 23:20:46 +03:00
using Microsoft.EntityFrameworkCore;
2023-05-16 22:09:57 +03:00
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
2023-05-11 23:20:46 +03:00
2023-05-15 20:45:16 +03:00
namespace NG_2023_Kanban.DataLayer.DbStartup
2023-05-11 23:20:46 +03:00
{
public static class Injecting
{
2023-05-16 22:09:57 +03:00
public static void InjectDAL(
2023-05-11 23:20:46 +03:00
this IServiceCollection services,
IConfiguration configuration)
{
2023-05-17 12:36:49 +03:00
services.AddTransient<IBoardRepository, BoardRepository>();
services.AddTransient<ICardRepository, CardRepository>();
services.AddTransient<IColumnRepository, ColumnRepository>();
services.AddTransient<ICommentRepository, CommentRepository>();
services.AddTransient<IUserRepository, UserRepository>();
var optionsBuilder = new DbContextOptionsBuilder<DatabaseContext>();
optionsBuilder.UseSqlServer(configuration["ConnectionString"]);
2023-05-11 23:20:46 +03:00
services.AddDbContext<DatabaseContext>(options =>
{
options.UseSqlServer(
configuration["ConnectionString"]);
});
2023-05-17 12:36:49 +03:00
(new DatabaseContext(optionsBuilder.Options)).Database.EnsureCreated(); // possibly misplaced
2023-05-11 23:20:46 +03:00
}
}
}