Skip to content
简体中文

Quickstart ​

Run this command from the repository root. See requirements for the SDK.

bash
dotnet run --project Samples/MinimalApp -c Release

The output shows a greeting from a standalone service, followed by the architecture startup and sample order processing.

Application entry point ​

cs
// Copyright (c) 2025-2026 GeWuYou
// SPDX-License-Identifier: Apache-2.0

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using MinimalApp;

// 最小非游戏应用样例:标准 DI + 标准日志。
// 演示两条相互独立的使用路径:
// 1) 完全不使用 Architecture:ServiceCollection + ILoggerFactory + ILogger<T>;
// 2) 可选使用 Architecture 编排:普通服务不要求 Model/System/Utility 角色,
//    组件通过构造注入获取 ILogger<T>,销毁时由架构释放实例日志工厂。

// 1) 纯标准路径:与任何普通 .NET 应用一致,框架不介入。
var services = new ServiceCollection();
services.AddSingleton<Greeter>();
services.AddLogging(builder => builder.AddSimpleConsole());

await using var provider = services.BuildServiceProvider();
var greeter = provider.GetRequiredService<Greeter>();
greeter.Greet("standalone");

// 2) Architecture 编排路径:实例日志工厂属于当前架构,销毁时释放。
// #region minimal-architecture
var architecture = new OrderArchitecture();
await architecture.InitializeAsync().ConfigureAwait(false);
architecture.PlaceDemoOrder("demo-0001");
await architecture.DestroyAsync().ConfigureAwait(false);
// #endregion minimal-architecture

Register application services ​

OrderArchitecture registers services in ConfigureServices. The host calls services after startup and awaits DestroyAsync on exit.

cs
// Copyright (c) 2025-2026 GeWuYou
// SPDX-License-Identifier: Apache-2.0

using GFramework.Core.Architectures;
using Microsoft.Extensions.DependencyInjection;

namespace MinimalApp;

/// <summary>
///     示例架构:只使用标准 DI 注册普通服务,不引入 Model/System/Utility 角色。
///     Architecture 在这里只提供实例级的初始化/停止编排与日志工厂所有权。
/// </summary>
internal sealed class OrderArchitecture : Architecture
{
    /// <summary>描述服务注册;此阶段只记录描述,不解析实例。</summary>
    /// <param name="services">当前架构将构建和拥有的服务集合。</param>
    protected override void ConfigureServices(IServiceCollection services)
    {
        // 普通服务:无角色标记、无 ContextAware、无基类要求。
        services.AddSingleton<OrderService>();
        services.AddSingleton<OrderProcessor>();
    }

    /// <summary>宿主准备完成后通过标准解析使用普通服务。</summary>
    protected override void OnStarted()
    {
        var processor = Services.GetRequiredService<OrderProcessor>();
        processor.Process("boot");
    }

    /// <summary>提交一条示例订单并输出处理日志。</summary>
    /// <param name="orderId">订单编号。</param>
    public void PlaceDemoOrder(string orderId)
    {
        var processor = Services.GetRequiredService<OrderProcessor>();
        processor.Process(orderId);
    }
}

For a new project, follow the installation guide to add Core, then register your application classes and their constructor dependencies in the composition root. For an engine project, run the Godot example next.

Apache License 2.0