> For the complete documentation index, see [llms.txt](https://docs.zongsoft.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zongsoft.com/hosting/hosting.md).

# 宿主概览

选择终端、后台或 Web 宿主，理解应用身份、配置目录和插件生命周期。

宿主提供进程入口、配置、服务容器、日志和启停生命周期，插件提供业务能力。保持宿主入口简洁，可以让同一业务组件在不同部署方案中复用；复用的前提是目标宿主具备它需要的交互或协议能力。

## 选择宿主

| 类型       | 主要入口                                                                                             | 适合场景             | 阅读                           |
| -------- | ------------------------------------------------------------------------------------------------ | ---------------- | ---------------------------- |
| Terminal | 交互命令                                                                                             | 开发调试、手工诊断、复现后台行为 | [终端宿主](/hosting/terminal.md) |
| Daemon   | 长期[工作器](https://github.com/Zongsoft/framework/blob/main/Zongsoft.Core/src/Components/IWorker.cs) | 消费消息、执行作业、系统服务   | [后台服务宿主](/hosting/daemon.md) |
| Web      | HTTP 管线                                                                                          | 控制器、接口、网关        | [Web 宿主](/hosting/web.md)    |

终端可模拟后台业务，但 Web 控制器和中间件仍需 Web 宿主；使用终端输入的插件也不应无条件在无交互服务中启动。

## 当前源码构建方式

hosting 根目录的 `Directory.Build.props` 当前设置 `net10.0`，并启用 `ZongsoftFrameworkPathReferenced`，从相邻 framework 的对应输出引用类库。构建宿主之前，需要准备匹配目标框架和编译配置的框架产物。

框架库本身可能支持 .NET 8、9、10，这不代表每个宿主项目和所有依赖均使用相同目标。切换版本时还要核对项目、中央包版本和发布脚本，参见[环境准备](/get-started/prerequisites.md)。

## 运行目录与身份

以 hosting/web/default 的实际部署清单为例，Main.plugin 放入 plugins，其他配置由 scheme、site、environment 等变量选择；Discussions 的部署位置见[部署第一个插件](/get-started/deploy-first-plugin.md)。

来源：[hosting/web/default/.deploy](https://github.com/Zongsoft/hosting/blob/main/web/default/.deploy#L7)（节选；上下文见源文件）。

{% code title=".deploy" %}

```ini
#@import ../web.deploy

[plugins]
nuget:Zongsoft.Plugins/plugins/Main.plugin
```

{% endcode %}

发布后的入口是 Zongsoft.Hosting.Web.dll，其依赖清单与运行时配置随 dotnet publish 生成。插件和 .option 文件由部署清单补齐，不能仅凭程序集文件存在认定部署完整。

可执行文件名、运行时应用名、`host` 和 `site` 不一定相同。应用名影响配置及升级匹配，`host/site` 参与部署和运行配置选择。终端当前应用名为 `zongsoft.terminal`，但入口程序集为 `Zongsoft.Hosting.Terminal`。

工作目录、应用目录和内容根路径也应分开理解，见[基础概念](/overview/concepts.md#host)。从其他目录启动服务时，错误的相对路径可能导致配置、数据库或插件资源解析到不同位置。

## 一次完整启动的验证

先确认进程正确启动，再检查插件加载、构件与服务注册，最后验证业务调用。某些提供者延迟建立连接，首次访问才会暴露端点、权限或 DLL 版本错误。

停止时，宿主通知[工作器](https://github.com/Zongsoft/framework/blob/main/Zongsoft.Core/src/Components/IWorker.cs)停止并释放自己拥有的资源。业务工作器应停止接收新任务、传递取消、等待必要的在途操作；不应靠强制退出代替正常生命周期设计。

下一步：[部署宿主](/hosting/deployment.md)、[容器化环境](/hosting/containerization.md)、[插件宿主集成](/framework/plugins/hosting.md)。

源码入口：[hosting 仓库](https://github.com/Zongsoft/hosting)。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.zongsoft.com/hosting/hosting.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
