CI / Go Backend (push) Canceled after 0s
初始化 monorepo: Go后端(7微服务) + Unity客户端(9模块) + 启动器 HTML5原型: Three.js 3D体素世界, Perlin噪声地形, 原版材质, 22种方块 Minecraft创造模式背包: 双栏布局, 拖拽移动物品, 方向性元件引脚 AI助搭策划文档 + 客户端/服务端骨架 + Docker Compose + CI
64 lines
1.8 KiB
C#
64 lines
1.8 KiB
C#
using System.Threading.Tasks;
|
|
|
|
namespace PCL.Core.App.IoC;
|
|
|
|
/// <summary>
|
|
/// General service class for constructing <see cref="ILifecycleService"/> in a more convenient way.
|
|
/// </summary>
|
|
public abstract class GeneralService : ILifecycleService
|
|
{
|
|
/// <inheritdoc/>
|
|
public string Identifier { get; }
|
|
|
|
/// <inheritdoc/>
|
|
public string Name { get; }
|
|
|
|
/// <inheritdoc/>
|
|
public bool SupportAsync { get; }
|
|
|
|
/// <summary>
|
|
/// The context of the service instance,
|
|
/// used for declaration, logging, lifecycle operation, etc.
|
|
/// </summary>
|
|
protected LifecycleContext ServiceContext { get; }
|
|
|
|
/// <summary>
|
|
/// Initialize a general service instance.
|
|
/// This constructor should only be extended rather than invoked directly.
|
|
/// </summary>
|
|
/// <param name="identifier">see <see cref="Identifier"/></param>
|
|
/// <param name="name">see <see cref="Name"/></param>
|
|
/// <param name="asyncStart">see <see cref="SupportAsync"/></param>
|
|
protected GeneralService(string identifier, string name, bool asyncStart = true)
|
|
{
|
|
Identifier = identifier;
|
|
Name = name;
|
|
SupportAsync = asyncStart;
|
|
ServiceContext = Lifecycle.GetContext(this);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Start the service, will be invoked on the specified state
|
|
/// from <see cref="LifecycleServiceAttribute.StartState"/> of <see cref="LifecycleServiceAttribute"/>.
|
|
/// </summary>
|
|
public virtual void Start() { }
|
|
|
|
/// <summary>
|
|
/// Stop the service, will be invoked while program exiting,
|
|
/// or if <see cref="Start"/> throws an exception.
|
|
/// </summary>
|
|
public virtual void Stop() { }
|
|
|
|
public Task StartAsync()
|
|
{
|
|
Start();
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task StopAsync()
|
|
{
|
|
Stop();
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|