BRAKING refactor project structure.

Refactor: the project is now divided into a more clear structure, with **Infrastructure** and **Application** layers added.

Refactor: configurations are split into sections for different layers.

Fix: now EF Core related operations, such as migration, should be invoked in `OptixServe.Infrastructure`, with config file and data dir passed into `dotnet ef` command. See `OptixServe.Infrastructure/Utilites/DesignTimeDbContextFactory.cs` for details.

Fix: EF migrations are ignored in gitignore on purpose in early development.
This commit is contained in:
2025-07-11 14:48:50 +08:00
parent 47cbdc21c1
commit 8b18de1735
20 changed files with 286 additions and 100 deletions

View File

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\OptixServe.Core\OptixServe.Core.csproj" />
<ProjectReference Include="..\OptixServe.Infrastructure\OptixServe.Infrastructure.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.6" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,31 @@
using OptixServe.Core.Models;
using OptixServe.Infrastructure.Data;
namespace OptixServe.Application.Services;
public interface IUserService
{
IEnumerable<User> GetUsers();
User? GetUserById(string id);
User? GetUserByUsername(string username);
}
public class UserService(AppDbContext dbContext) : IUserService
{
private readonly AppDbContext _dbContext = dbContext;
public User? GetUserById(string id)
{
return _dbContext.Users.FirstOrDefault(u => u.Id == id);
}
public User? GetUserByUsername(string username)
{
return _dbContext.Users.FirstOrDefault(u => u.UserName == username);
}
public IEnumerable<User> GetUsers()
{
return _dbContext.Users.AsEnumerable();
}
}