Cnfzh 软件博客
用 .NET 10 与 Blazor 搭建一套可复用的博客框架

用 .NET 10 与 Blazor 搭建一套可复用的博客框架

从分层设计到自动 API,聊一聊如何把通用基础设施抽离成独立框架,让业务项目只关心业务。

为什么要抽离框架

业务项目最容易膨胀的地方,往往不是业务本身,而是一遍遍重写的横切能力:统一返回、动态 API、依赖注入约定、限流、审计字段。

把它们沉淀到独立的 Cnfzh 框架项目里,业务层就只剩下三件事:实体、应用服务、页面。

分层依赖

BSUI → Application → Core → Cnfzh

依赖严格单向向下,框架对业务零感知——它不知道有博客,也不知道有文章。

自动 API

应用服务只要实现 IFzAutoApi,每个 public 方法就是一个端点:

public class PostAppService : IFzAutoApi
{
    public Task<PagedResult<PostDto>> GetPagedAsync(PostQueryInput input) => ...;
}

同一份契约,Blazor 后台在进程内直接调用,Vue / 小程序则走 /api/post/Paged,不必写两份。

评论 1

a a
test
提交前需验证邮箱,验证码 10 分钟内有效。

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.