Skip to content

Commit

Permalink
update ater.web docs
Browse files Browse the repository at this point in the history
  • Loading branch information
niltor committed Feb 29, 2024
1 parent 53ac79d commit 3dcb6a5
Show file tree
Hide file tree
Showing 15 changed files with 491 additions and 484 deletions.
76 changes: 38 additions & 38 deletions en/ater.dry/toc.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
# This is an automatically generated file
items:
- name: Ater.Dry
href: Overview.md
- name: Install
href: Install.md
- name: Create and run project
href: Create and Run Project.md
- name: Ater.Dry
href: Overview.md
- name: Installation
href: Install.md
- name: Studio
href: Studio/Dry Studio.md
items:
- name: Dry Studio
href: Studio/Dry Studio.md
- name: 疑难问题
href: Studio/疑难问题.md
- name: 配置说明
href: Studio/配置说明.md
- name: 高级自定义功能
href: Studio/高级自定义功能.md
- name: Command line
href: Command line/Dto生成.md
items:
- name: Dto
href: Command line/Dto生成.md
- name: Manager
href: Command line/Manager生成.md
- name: WebApi
href: Command line/控制器接口生成.md
- name: Request
href: Command line/前端请求服务生成.md
- name: Studio
href: Studio/Use Dry Studio.md
items:
- name: Using Dry Studio
href: Studio/Use Dry Studio.md
- name: configuration description
href: Studio/Configuration Description.md
- name: Problem
href: Studio/Trouble.md
- name: Advanced Custom Features
href: Studio/Advanced customization.md
- name: code generation description
href: Code Generation Instructions/DTO Generation.md
items:
- name: DTO generation description
href: Code Generation Instructions/DTO Generation.md
- name: Manager Code Generation Description
href: Code Generation Description/Manager Generation.md
- name: Command line
href: Command line/Dto generate.md
items:
- name: Dto
href: Command line/Dto generate.md
- name: Manager
href: Command Line/Manager Generates.md
- name: WebApi
href: Command Line/Controller Interface Generation.md
- name: Request
href: Command Line/Front End Request Service Generation.md
- name: Studio
href: Command line/Studio.md
- name: Config
href: Command Line/Configuration.md
href: Command line/Studio.md
- name: Config
href: Command line/配置.md
- name: Code Generation Instructions
href: Code Generation Instructions/DTO生成.md
items:
- name: DTO生成说明
href: Code Generation Instructions/DTO生成.md
- name: Manager代码生成说明
href: Code Generation Instructions/Manager生成.md
- name: Create and run projects
href: Create and run project.md
4 changes: 2 additions & 2 deletions en/ater.web/.order
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
概述
Overview
教程
快速入门
Quick Start
约定和规范
示例
自定义
Expand Down
75 changes: 75 additions & 0 deletions en/ater.web/Overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# What is Ater.Web?

`Ater.Web.template`is an out-of-the-box solution template based on`ASP.NET Core`,`Entity Framework`, and`.NET Aspire`, combined with a large number of project practices to help new and old developers quickly develop application services.

## characteristics

- Based on official technology, it is not`另一个框架`, and it is extremely versatile.
- Templates include all source code, no`框架依赖包`, transparency and focus.
- For the purpose of development and maintenance efficiency, it provides layered project structure and code practice specifications, which are suitable for various scenarios such as single application, microservice, multi-person collaboration, etc.
- Provide intelligent code assistant tools to minimize repetitive work.

>**Summary: simple, universal, practical!**
## What can it do for you?

- Quickly build a working project and provide common configuration and dependency injection.
- It provides a practical way to better organize your code, while achieving separation of concerns and improving development and maintenance efficiency.
- Learning and building general knowledge systems rather than learning and using specific usage.
- DRY(don't repeat yourself), which uses intelligent code assistants to generate code for you to save time.
- Help team members get started on projects quickly, even if they are new to them, and quickly implement the business.

## The following may not apply

- Templates do not provide functionality integrations that are available without development, such as payments, CMS, authentication, etc. You need to select other options and integrate them.
- Much of our code implementation and generation is based on`Entity Framework`, and if you don't use it, you won't enjoy the convenience.
- Does not apply to interface development using`minimalAPI`style.
- The new template is based on`.NET8.0`, and older versions do not apply.

> [!NOTE]
>Using this set of templates and development tools, your development work will be simple and orderly, with a business implementation you only need to:
>
>- Define solid model
>- Template code generation via tools (e.g. DTO, basic CURD, interfaces).
>- Adjust and implement your own business logic according to the actual business.
>- Define exposed interfaces
## installation

premise

- Install[`.NET SDK 8.0`](https://dotnet.microsoft.com/zh-cn/download)

Install using`dotnet new`command.

```pwsh
dotnet new install ater.web.templates
```

## use

After installation, you can create a project using the command or by selecting Create via VS's graphical interface (recommended).

```pwsh
dotnet new atapi -n my-project
```

Go to`Http.API` project and configure the database connection string in`appsetings.json`

> [!TIP]
>`PostgreSQL`is used by default. Please change it according to your actual needs.
## Install ater.dry (recommended)

`ater.dry`is an intelligent code assistance tool, mainly provides code generation function, it can analyze your entity, intelligently help you generate related data transfer objects, database read and write operations and API interfaces. It is provided by`dotnet` command-line tools, while providing Web UI interface, can save a lot of development time, strongly recommended installation use!

```pwsh
dotnet tool install --global ater.dry
```

> [!TIP]
>This tool provides out-of-the-box support for`Ater.Web`templates!
## next step

🎉Congratulations on the successful completion of the project creation, to understand the[project structure](./%E6%95%99%E7%A8%8B/%E9%A1%B9%E7%9B%AE%E7%BB%93%E6%9E%84%E8%AF%B4%E6%98%8E.md)!
158 changes: 158 additions & 0 deletions en/ater.web/Quick Start.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# Quick Start

Precondition: You have installed and created a project template

## Check the configuration file

Templates default to`PostgreSQL` as a relational database and`Redis` as distributed cache support.

You need to configure the connection string in`appsettings.json`and replace the default database if you want.

## Defining Solid Models

- Defining a solid model under an`Entity`project
- Define database context and`DbSet`under`EntityFramework`project

> [!IMPORTANT]
>Please follow the official documentation of`Entity Framework Core`to define models and relationships.
## Generate base code

Use`dry studio` to generate`dto`,`Manager`,`Controller` and other basic code.

> [!TIP]
>For more information about`dry cli`, see[the dry cli documentation.](https://docs.dusi.dev/zh/ater.dry/%E6%A6%82%E8%BF%B0.html)
## Implement custom business logic

Implement business logic in the`Application``Manager`directory, usually including`筛选查询`,`添加实体`, and`更新实体`.

### Filter query

Steps to build custom query criteria:

1. Construct your own query condition`Queryable`
2. Call`FilterAsync<T>` method to get results

Code example:

```csharp

public override async Task<PageList<DiscussItemDto>> FilterAsync(DiscussFilterDto filter)
{
// 根据实际业务构建筛选条件
if (filter.IsTop != null)
{
Queryable = Queryable.Where(q => q.IsTop == filter.IsTop);
}
if (filter.MemberId != null)
{
Queryable = Queryable.Where(q => q.Member.Id == filter.MemberId);
}
return await Query.FilterAsync<DiscussItemDto>(Queryable, filter.PageIndex, filter.PageSize);
}
```

### Additional entity

Code example:

```csharp
public override async Task<Discuss> AddAsync(Discuss entity)
{
var res = await Command.CreateAsync(entity);
// TODO: do something
// 提交更新
await Command.SaveChangeAsync();
return res;
}
```

### Updating the entity

`manager`provides a`GetCurrent` method to get the current (`可写数据库上下文`) entity.

In the controller, the entity will be obtained first. If it does not exist, it will directly return to`404`.

The entity update method passes two parameters, one for the entity itself and one for the submitted`DTO` object.
The entity itself is obtained by using`GetCurrent` method in the controller, and can be passed directly as a parameter.

Code example:

The following aspects demonstrate how to update associated content.

```csharp
public override async Task<ResourceTypeDefinition> UpdateAsync(ResourceTypeDefinition entity, ResourceTypeDefinitionUpdateDto dto)
{
// 更新关联的内容
entity!.AttributeDefines = null;
if (dto.AttributeDefineIds != null)
{
// 通过父类的 Stores 查询其他实体的内容
var attributeDefines = await Stores.ResourceAttributeDefineCommand.Db.Where(a => dto.AttributeDefineIds.Contains(a.Id)).ToListAsync();
entity.AttributeDefines = attributeDefines;
}
return await base.UpdateAsync(entity, dto);
}
```

### For more information

`manager`provides default query method for details, which can directly pass query conditions.

If you customize queries, such as querying associated content, you need to add new methods to implement them.

`manager`provides`Query.Db` members to query directly against the current model.

Code example:

```csharp
public async Task<ResourceGroup?> FindAsync(Guid id)
{
return await Query.Db
.Include(g => g.Environment)
.FirstOrDefaultAsync(g => g.Id == id);
}
```

### Deletion processing

Delete defaults to soft delete, and if you want to modify this behavior, set`EnableSoftDelete` to false in`CommandStoreBase`class.

If you want to cancel only for an entity, you can override`EnableSoftDelete`in the`XXXCommandStore`class corresponding to the entity and set it to false.

Deletion sometimes involves**association deletion**, example code:

```csharp
public override async Task<Resource?> DeleteAsync(Guid id)
{
var resource = entity;
if (resource!.Attributes != null)
{
Stores.CommandContext.RemoveRange(resource.Attributes);
}
return await DeleteAsync(resource);
}

```

## Call business logic in controller

After you implement the business interface and implementation in`Application`, you can call the related business methods in the interface class in`Http.API`through dependency injection.

> [!NOTE]
>Please keep the code of the controller clean and avoid`查询数据库、实现业务逻辑`directly in the controller.
## Perform the migration

After you add or modify entities, you need to perform a database migration for the database structure changes to take effect.

You can use`dotnet ef` command to generate migration scripts.

> [!IMPORTANT]
>Database migration is required under`Http.API`project.
Or you can simply execute the migration generation`script/EFMigrations.ps1`we provide.

> [!TIP]
>You don't need to execute`dotnet ef update` because the program commits changes automatically when it starts.
12 changes: 7 additions & 5 deletions en/ater.web/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ items:
- name: 项目结构说明
href: 教程/项目结构说明.md
- name: 分层项目说明
href: 教程/分层项目说明/Entity.md
href: 教程/分层项目说明/Infrastructure.md
items:
- name: Entity
href: 教程/分层项目说明/Entity.md
- name: Share
href: 教程/分层项目说明/Share.md
- name: Infrastructure
href: 教程/分层项目说明/Infrastructure.md
- name: Definition
href: 教程/分层项目说明/Definition.md
- name: Application
href: 教程/分层项目说明/Application.md
- name: Http.API
Expand All @@ -27,6 +27,8 @@ items:
items:
- name: 实体定义
href: 约定和规范/实体定义.md
- name: 第三方依赖
href: 约定和规范/第三方依赖.md
- name: 约定
href: 约定和规范/约定.md
- name: 示例
Expand Down
Loading

0 comments on commit 3dcb6a5

Please sign in to comment.