Implement N-layer architecture
This commit is contained in:
parent
6dfa6908b1
commit
16ef307140
96 changed files with 132 additions and 28 deletions
|
@ -0,0 +1,13 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../NG_2023_Kanban.DataLayer/NG_2023_Kanban.DataLayer.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
33
NG_2023_Kanban.BusinessLayer/Service/BusinessService.cs
Normal file
33
NG_2023_Kanban.BusinessLayer/Service/BusinessService.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using NG_2023_Kanban.DataLayer.Service;
|
||||
using NG_2023_Kanban.DataLayer.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace NG_2023_Kanban.BusinessLayer.Service
|
||||
{
|
||||
public class BusinessService
|
||||
{
|
||||
private readonly DataService _service;
|
||||
public BusinessService(DataService service)
|
||||
{
|
||||
_service = service;
|
||||
}
|
||||
|
||||
public async Task<User> LoginAsync(string username, string password)
|
||||
{
|
||||
return await _service.LoginAsync(username, password);
|
||||
}
|
||||
|
||||
public async Task<User> RegisterAsync(string fullName, string username, string password)
|
||||
{
|
||||
User account = await _service.AddAsync(new User
|
||||
{
|
||||
FullName = fullName,
|
||||
Username = username,
|
||||
Password = password, // TODO: hashing
|
||||
IsAdmin = false
|
||||
});
|
||||
|
||||
return account;
|
||||
}
|
||||
}
|
||||
}
|
14
NG_2023_Kanban.BusinessLayer/Service/Injecting.cs
Normal file
14
NG_2023_Kanban.BusinessLayer/Service/Injecting.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using NG_2023_Kanban.BusinessLayer.Service;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace NG_2023_Kanban.BusinessLayer.Inject
|
||||
{
|
||||
public static class Injecting
|
||||
{
|
||||
public static void InjectBLL(
|
||||
this IServiceCollection services)
|
||||
{
|
||||
services.AddScoped<BusinessService>();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +1,13 @@
|
|||
using NG_2023_Kanban.BusinessLayer.Service;
|
||||
using NG_2023_Kanban.DataLayer.Service;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace NG_2023_Kanban.DataLayer.DbStartup
|
||||
{
|
||||
public static class Injecting
|
||||
{
|
||||
public static void Inject(
|
||||
public static void InjectDAL(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
|
@ -14,7 +16,7 @@ namespace NG_2023_Kanban.DataLayer.DbStartup
|
|||
options.UseSqlServer(
|
||||
configuration["ConnectionString"]);
|
||||
});
|
||||
services.AddScoped<DbService>();
|
||||
services.AddScoped<DataService>();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,7 +18,8 @@ namespace NG_2023_Kanban.DataLayer.EntityConfiguration
|
|||
.HasOne(x => x.Sender)
|
||||
.WithMany(x => x.Comments)
|
||||
.HasForeignKey(x => x.SenderId)
|
||||
.HasPrincipalKey(x => x.Id);
|
||||
.HasPrincipalKey(x => x.Id)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder
|
||||
.HasOne(x => x.Card)
|
|
@ -1,15 +1,14 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.5" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -2,14 +2,15 @@
|
|||
using NG_2023_Kanban.DataLayer.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace NG_2023_Kanban.BusinessLayer.Service
|
||||
namespace NG_2023_Kanban.DataLayer.Service
|
||||
{
|
||||
public class DbService
|
||||
public class DataService
|
||||
{
|
||||
private readonly DatabaseContext _context;
|
||||
public DbService(DatabaseContext context)
|
||||
public DataService(DatabaseContext context)
|
||||
{
|
||||
_context = context;
|
||||
_context.Database.EnsureCreated();
|
||||
}
|
||||
|
||||
public async Task<User> AddAsync(User entity)
|
34
NG_2023_Kanban.sln
Normal file
34
NG_2023_Kanban.sln
Normal file
|
@ -0,0 +1,34 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.31903.59
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NG_2023_Kanban", "NG_2023_Kanban\NG_2023_Kanban.csproj", "{9487AF5A-D980-4015-B8EE-BF243BC0534E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NG_2023_Kanban.BusinessLayer", "NG_2023_Kanban.DataLayer\NG_2023_Kanban.BusinessLayer.csproj", "{B62FD923-EDD7-4A4E-AD73-408C2FD0AC2B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NG_2023_Kanban.BusinessLayer", "NG_2023_Kanban.BusinessLayer\NG_2023_Kanban.BusinessLayer.csproj", "{169BEBE0-05F8-463D-999E-323F37454289}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9487AF5A-D980-4015-B8EE-BF243BC0534E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9487AF5A-D980-4015-B8EE-BF243BC0534E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9487AF5A-D980-4015-B8EE-BF243BC0534E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9487AF5A-D980-4015-B8EE-BF243BC0534E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B62FD923-EDD7-4A4E-AD73-408C2FD0AC2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B62FD923-EDD7-4A4E-AD73-408C2FD0AC2B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B62FD923-EDD7-4A4E-AD73-408C2FD0AC2B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B62FD923-EDD7-4A4E-AD73-408C2FD0AC2B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{169BEBE0-05F8-463D-999E-323F37454289}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{169BEBE0-05F8-463D-999E-323F37454289}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{169BEBE0-05F8-463D-999E-323F37454289}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{169BEBE0-05F8-463D-999E-323F37454289}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -5,14 +5,14 @@ using NG_2023_Kanban.Extensions;
|
|||
using NG_2023_Kanban.DataLayer.Models;
|
||||
using NG_2023_Kanban.BusinessLayer.Service;
|
||||
|
||||
namespace NG_2023_Kanban.PresentationLayer.Controllers;
|
||||
namespace NG_2023_Kanban.Controllers;
|
||||
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly DbService _service;
|
||||
private readonly BusinessService _service;
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger, DbService service)
|
||||
public HomeController(ILogger<HomeController> logger, BusinessService service)
|
||||
{
|
||||
_logger = logger;
|
||||
_service = service;
|
||||
|
@ -82,13 +82,7 @@ public class HomeController : Controller
|
|||
|
||||
try
|
||||
{
|
||||
User account = await _service.AddAsync(new User
|
||||
{
|
||||
FullName = fullName,
|
||||
Username = username,
|
||||
Password = password, // TODO: hashing
|
||||
IsAdmin = false
|
||||
});
|
||||
User account = await _service.RegisterAsync(fullName, username, password);
|
||||
|
||||
HttpContext.Session.SetObject("Account", account);
|
||||
return Redirect("/Home/Index");
|
18
NG_2023_Kanban/NG_2023_Kanban.csproj
Normal file
18
NG_2023_Kanban/NG_2023_Kanban.csproj
Normal file
|
@ -0,0 +1,18 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../NG_2023_Kanban.DataLayer/NG_2023_Kanban.DataLayer.csproj" />
|
||||
<ProjectReference Include="../NG_2023_Kanban.BusinessLayer/NG_2023_Kanban.BusinessLayer.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -1,10 +1,12 @@
|
|||
using NG_2023_Kanban.BusinessLayer.Inject;
|
||||
using NG_2023_Kanban.DataLayer.DbStartup;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
IConfiguration configuration = builder.Configuration;
|
||||
|
||||
builder.Services.Inject(configuration);
|
||||
builder.Services.InjectDAL(configuration);
|
||||
builder.Services.InjectBLL();
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
|
@ -27,13 +29,6 @@ if (!app.Environment.IsDevelopment())
|
|||
app.UseHsts();
|
||||
}
|
||||
|
||||
using(var scope = app.Services.CreateScope())
|
||||
{
|
||||
var serviceProvider = scope.ServiceProvider;
|
||||
var context = serviceProvider.GetRequiredService<DatabaseContext>();
|
||||
DbInitializer.Initialize(context);
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
Reference in a new issue