使用 DDD 模式和 CleanArchitecture 设计理念
使用 .net 8 进行开发
项目模板: 类库
安装使用的包
- AutoMapper
- FluentValidation.DependencyInjectionExtensions
- MediatR
- Microsoft.EntityFrameworkCore
依赖 Domain
Common.Exceptions
-
NotFoundException
404 报错说明文件
-
ValidationException
验证器抛出 message 文件
Common.Interfaces
-
IApplicationDbContext
实体映射接口
Common.Mappings
-
IMapFrom
AutoMapper 映射公共接口
-
MappingExtensions
分页查询公共方法
-
MappingProfile
自动扫描并注册所有实现了 IMapFrom<> 或 IMapTo<> 接口的类型
Common.Models
-
PaginatedList
分页搜索公共类
UserProfiles
示例增删改查接口
DependencyInjection
Application 层的服务注册
GlobalUsings
公共 using 引用类
项目模板: 类库
安装使用的包
- MediatR.Contracts
项目模板: 类库
安装使用的包
- Microsoft.EntityFrameworkCore
- Microsoft.EntityFrameworkCore.SqlServer
依赖 Application
项目模板: ASP.NET Core Web API
安装使用的包
- Microsoft.EntityFrameworkCore.Design
- Microsoft.EntityFrameworkCore.Tools
- Swashbuckle.AspNetCore
依赖 Application , Infrastructure
zustand 登录状态全局管理
import { create } from 'zustand'
import { persist } from 'zustand/middleware'
interface AuthState {
isAuthenticated: boolean
user: { id?: number; email?: string } | null
token: string | null
login: (user: { id?: number; email?: string }, token: string) => void
logout: () => void
}
export const useAuthStore = create<AuthState>()(
persist(
(set) => ({
isAuthenticated: false,
user: null,
token: null,
login: (user, token) =>
set({
isAuthenticated: true,
user,
token,
}),
logout: () =>
set({
isAuthenticated: false,
user: null,
token: null,
}),
}),
{
name: 'auth-storage',
}
)
)