Expand description
Application builder for constructing DMSC applications Copyright © 2025-2026 Wenze Wei. All Rights Reserved.
This file is part of DMSC. The DMSC project belongs to the Dunimd Team.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
§Application Builder
This module provides the application builder for constructing DMSC applications.
The DMSCAppBuilder follows the builder pattern for fluent configuration,
enabling developers to compose applications from various modules, configuration
sources, and runtime settings in a declarative manner.
§Builder Pattern
The builder pattern allows step-by-step construction of complex objects.
Each method on DMSCAppBuilder configures a specific aspect of the application
and returns the builder for method chaining. This results in a fluent API
that is both readable and type-safe.
§Module Registration
Modules are the primary extension point for DMSC applications. The builder supports multiple types of modules:
- Synchronous modules: Implement
ServiceModuletrait for sync operations - Asynchronous modules: Implement
AsyncServiceModuletrait for async operations - DMSC modules: Implement public
DMSCModuletrait (converted to async internally) - Python modules: Modules created from Python code (with pyo3 feature)
§Configuration Management
The builder supports multiple configuration sources with a defined priority order:
- Configuration files (lowest priority):
dms.yaml,dms.yml,dms.toml,dms.json - Custom configuration via
with_config()method - Environment variables (highest priority)
§Usage Example
use dmsc::prelude::*;
#[tokio::main]
async fn main() -> DMSCResult<()> {
let app = DMSCAppBuilder::new()
.with_config("config.yaml")?
.with_module(Box::new(MySyncModule::new()))
.with_async_module(Box::new(MyAsyncModule::new()))
.build()?;
app.run(|ctx| async move {
ctx.logger().info("service", "DMSC service started")?;
Ok(())
}).await
}§Thread Safety
The DMSCAppBuilder is designed to be used in a single-threaded context
during application construction. After calling build(), the resulting
DMSCAppRuntime is safe to use across multiple threads.
§Error Handling
All builder methods that can fail return DMSCResult, enabling proper
error handling through the ? operator or explicit match statements.
Structs§
- DMSC
AppBuilder - Public-facing application builder for DMSC.