应用服务 logo

应用服务

Organization
microwind
应用服务

应用层的服务,负责用例编排、事务管理和协调领域对象,不包含业务逻辑。

Overview

Publishermicrowind
Repositoryai-skills
Skill name应用服务
Stars
93
Forks
25
Bundled files
Instructions only
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by microwind on GitHub. Read the source before you install it.

Installation

Install the 应用服务 AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/microwind/ai-skills/tree/main/domain-driven-design/application-service
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/microwind/ai-skills.git /tmp/ai-skills
mkdir -p .claude/skills
cp -r /tmp/ai-skills/domain-driven-design/application-service .claude/skills/microwind-57
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable 应用服务 in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads 应用服务 on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so 应用服务 is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

应用服务 (Application Service)

概述

应用服务是应用层的协调者,负责把一个用例(Use Case)从入口到出口编排完整。它本身不包含业务规则——业务规则由聚合、领域服务负责;应用服务只负责调度、事务、安全、消息发布等"管道工作"。

职责:

  • 接收外部请求(DTO / Command)
  • 校验权限与输入完整性(非业务规则)
  • 加载领域对象(通过仓储)
  • 调用领域对象 / 领域服务执行业务逻辑(业务规则在领域层)
  • 划定事务边界(一次用例 = 一个事务 = 一个聚合实例的写)
  • 发布领域事件 / 集成事件
  • 返回结果(DTO,不暴露领域对象)

经验法则:应用服务应当是薄层——一个方法通常不超过十几行;如果膨胀,说明业务逻辑泄漏到了应用层。

代码示例

java
@Service
@Transactional
public class OrderApplicationService {
    private final OrderRepository orderRepo;
    private final CustomerRepository customerRepo;
    private final EventPublisher eventPublisher;

    // 用例:下单
    public OrderDTO placeOrder(PlaceOrderCommand cmd) {
        // 1. 加载领域对象
        Customer customer = customerRepo.findById(cmd.getCustomerId())
            .orElseThrow(() -> new NotFoundException("客户不存在"));
        Order order = orderRepo.findById(cmd.getOrderId())
            .orElseThrow(() -> new NotFoundException("订单不存在"));

        // 2. 调用领域逻辑(逻辑在 Order 中)
        order.place();

        // 3. 持久化
        orderRepo.save(order);

        // 4. 发布事件
        order.getDomainEvents().forEach(eventPublisher::publish);
        order.clearDomainEvents();

        // 5. 返回 DTO
        return OrderDTO.from(order);
    }

    // 用例:取消订单
    public void cancelOrder(CancelOrderCommand cmd) {
        Order order = orderRepo.findById(cmd.getOrderId())
            .orElseThrow(() -> new NotFoundException("订单不存在"));

        order.cancel(cmd.getReason());  // 业务逻辑在领域对象中

        orderRepo.save(order);
        order.getDomainEvents().forEach(eventPublisher::publish);
        order.clearDomainEvents();
    }
}
python
class OrderApplicationService:
    def __init__(self, order_repo, customer_repo, event_publisher):
        self.order_repo = order_repo
        self.customer_repo = customer_repo
        self.event_publisher = event_publisher

    def place_order(self, cmd: PlaceOrderCommand) -> OrderDTO:
        customer = self.customer_repo.find_by_id(cmd.customer_id)
        if not customer:
            raise NotFoundError("客户不存在")

        order = self.order_repo.find_by_id(cmd.order_id)
        order.place()  # 业务逻辑在领域对象中

        self.order_repo.save(order)
        for event in order.collect_events():
            self.event_publisher.publish(event)

        return OrderDTO.from_domain(order)

应用服务 vs 领域服务

❌ 应用服务中写业务逻辑
public OrderDTO placeOrder(PlaceOrderCommand cmd) {
    Order order = orderRepo.findById(cmd.getOrderId());
    // 业务逻辑泄漏到应用层!
    if (order.getItems().isEmpty()) throw new Exception("订单为空");
    if (order.getStatus() != DRAFT) throw new Exception("状态错误");
    order.setStatus(PLACED);
    order.setTotalAmount(calculateTotal(order));
}

✅ 应用服务只做编排
public OrderDTO placeOrder(PlaceOrderCommand cmd) {
    Order order = orderRepo.findById(cmd.getOrderId());
    order.place();  // 所有业务逻辑在 Order 内部
    orderRepo.save(order);
}
维度应用服务领域服务
层次应用层领域层
职责编排用例流程纯业务逻辑
事务管理事务边界不管事务
依赖Repository, EventPublisher只依赖领域对象
业务逻辑不包含包含(跨实体的)

最佳实践

  1. 应用服务是薄层 — 如果应用服务很厚,说明业务逻辑泄漏了
  2. 一个方法 = 一个用例 — placeOrder, cancelOrder, shipOrder
  3. 输入用 Command/DTO — 不传领域对象给外部
  4. 输出用 DTO — 不直接返回领域对象

常见误区

❌ 应用服务里写业务规则——if (order.getStatus() != PENDING) throw ... → 业务规则归领域对象,应用服务只调用 order.pay()

❌ 直接返回领域对象——把 Order 序列化为 HTTP 响应 → 在边界处转换为 DTO,避免把内部模型暴露给外部

❌ 应用服务调用另一个应用服务——同层耦合、事务边界混乱 → 一个用例 = 一个应用服务方法;要复用就抽到领域服务或下层

与其他DDD概念的关系

概念关系
领域服务应用服务调用领域服务
仓储应用服务通过仓储加载/保存聚合
领域事件应用服务负责发布领域事件

总结

核心:应用服务 = 用例编排器,不含业务逻辑。

模式:加载对象 → 调用领域方法 → 保存 → 发布事件 → 返回DTO。

Frequently asked questions

What does the 应用服务 AI skill do?

应用层的服务,负责用例编排、事务管理和协调领域对象,不包含业务逻辑。

Why use 应用服务 on TypingMind?

Because you install it once and use it with any model. 应用服务 is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install 应用服务 in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/microwind/ai-skills/tree/main/domain-driven-design/application-service. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use 应用服务?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with 应用服务?

As many as you like. As long as a model supports skills, you can use 应用服务 with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the 应用服务 AI skill free?

It is published on GitHub by microwind. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇