Skip to main content

SERVICE_STUB

Constant SERVICE_STUB 

Source
pub const SERVICE_STUB: &str = r#"//! {%namespace%}::{%className%} 服务
//!
//! 由 `sz-rust make:service` 生成,对齐 PHP `make:service`。
//! 通过 `Container::singleton::<{%className%}>()` 注册后可在控制器中自动注入。

/// {%className%} 服务
///
/// 对齐 PHP `class {%className%} { public function __construct() {} }`。
pub struct {%className%};

impl {%className%} {
    /// 创建服务实例
    pub fn new() -> Self {
        Self
    }

    /// 业务方法示例
    ///
    /// 在此实现具体业务逻辑。
    pub fn execute(&self) -> Result<(), String> {
        // 在此实现业务逻辑
        Ok(())
    }
}

impl Default for {%className%} {
    fn default() -> Self {
        Self::new()
    }
}
"#;
Expand description

Service 模板(对齐 PHP make:service

PHP 原文生成含 __construct 与业务方法的服务类,Rust 生成可注入容器的服务结构体。