Skip to content

Commit b77232b

Browse files
committed
docs(readme): add FlowInterops.Run usage
1 parent 5e23605 commit b77232b

1 file changed

Lines changed: 48 additions & 1 deletion

File tree

‎README.md‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
面向现代 .NET 应用程序的轻量级生命周期与流程控制框架。
44

5+
*[WORKING IN PROGRESS]*
6+
57
[![NuGet Version](https://img.shields.io/nuget/v/FlowNet.Core?style=flat-square)](https://www.nuget.org/packages/FlowNet.Core)
68
[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ruattd/FlowNet/ci.yml?style=flat-square&label=ci)](https://github.com/ruattd/FlowNet/actions/workflows/ci.yml)
79
[![GitHub top language](https://img.shields.io/github/languages/top/ruattd/FlowNet?style=flat-square)](https://github.com/ruattd/FlowNet)
@@ -18,6 +20,7 @@ dotnet add package FlowNet.Core
1820

1921
```csharp
2022
using FlowNet.Core;
23+
using System.Threading.Tasks;
2124

2225
namespace YourApp.Namespace;
2326

@@ -39,4 +42,48 @@ public sealed partial class Program
3942

4043
然后就可以开始写业务逻辑了——就这么简单,简单到连 template 都不用。
4144

42-
*WORKING IN PROGRESS*
45+
## 基于流程的开发
46+
47+
将 Program 类改成这样:
48+
49+
```csharp
50+
using FlowNet.Core;
51+
using System.Threading.Tasks;
52+
53+
namespace YourApp.Namespace;
54+
55+
[Flow.Scope("app")]
56+
internal static partial class Program
57+
{
58+
// Run application based on flow control
59+
public static Task Main() => FlowInterops.Run();
60+
61+
// Define base flows
62+
[Flow.Task]
63+
[Flow.Task("loading")]
64+
[Flow.Task("exit")]
65+
private static Task Wildcard() => Task.CompletedTask;
66+
}
67+
```
68+
69+
然后使用 `Flow.Run` 标记来定义各流程间的依赖关系,例如:
70+
71+
```csharp
72+
using FlowNet.Core;
73+
using System.Threading.Tasks;
74+
75+
namespace YourApp.Namespace;
76+
77+
[Flow.Scope("config")]
78+
public sealed partial class ConfigService
79+
{
80+
[Flow.Task]
81+
[Flow.Run(After = "app:loading", Before = "*:start")]
82+
private static async Task _()
83+
{
84+
// 这是一个特殊的 Flow 任务,按照一般的标识符推断规则,它的标识符是空的
85+
// 因此这个任务的全局标识就是外部 scope 的标识,即 config
86+
// Initialize config service...
87+
}
88+
}
89+
```

0 commit comments

Comments
 (0)