Skip to content

Commit 1f52aae

Browse files
committed
feat: add modular application shell
1 parent fb48209 commit 1f52aae

28 files changed

Lines changed: 963 additions & 223 deletions
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using ChengYuan.Core.Modularity;
2+
3+
namespace ChengYuan.Core.Lifecycle;
4+
5+
public interface IModuleInitializationContext
6+
{
7+
IServiceProvider ServiceProvider { get; }
8+
9+
IModuleCatalog ModuleCatalog { get; }
10+
11+
CancellationToken CancellationToken { get; }
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using ChengYuan.Core.Modularity;
2+
3+
namespace ChengYuan.Core.Lifecycle;
4+
5+
public interface IModuleShutdownContext
6+
{
7+
IServiceProvider ServiceProvider { get; }
8+
9+
IModuleCatalog ModuleCatalog { get; }
10+
11+
CancellationToken CancellationToken { get; }
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace ChengYuan.Core.Lifecycle;
2+
3+
public interface IOnModuleInitialize
4+
{
5+
Task InitializeAsync(IModuleInitializationContext context);
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace ChengYuan.Core.Lifecycle;
2+
3+
public interface IOnModulePostInitialize
4+
{
5+
Task PostInitializeAsync(IModuleInitializationContext context);
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace ChengYuan.Core.Lifecycle;
2+
3+
public interface IOnModulePreInitialize
4+
{
5+
Task PreInitializeAsync(IModuleInitializationContext context);
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace ChengYuan.Core.Lifecycle;
2+
3+
public interface IOnModuleShutdown
4+
{
5+
Task ShutdownAsync(IModuleShutdownContext context);
6+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using ChengYuan.Core.Modularity;
2+
3+
namespace ChengYuan.Core.Lifecycle;
4+
5+
public sealed class ModuleInitializationContext(
6+
IServiceProvider serviceProvider,
7+
IModuleCatalog moduleCatalog,
8+
CancellationToken cancellationToken) : IModuleInitializationContext
9+
{
10+
public IServiceProvider ServiceProvider { get; } = serviceProvider;
11+
12+
public IModuleCatalog ModuleCatalog { get; } = moduleCatalog;
13+
14+
public CancellationToken CancellationToken { get; } = cancellationToken;
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using ChengYuan.Core.Modularity;
2+
3+
namespace ChengYuan.Core.Lifecycle;
4+
5+
public sealed class ModuleShutdownContext(
6+
IServiceProvider serviceProvider,
7+
IModuleCatalog moduleCatalog,
8+
CancellationToken cancellationToken) : IModuleShutdownContext
9+
{
10+
public IServiceProvider ServiceProvider { get; } = serviceProvider;
11+
12+
public IModuleCatalog ModuleCatalog { get; } = moduleCatalog;
13+
14+
public CancellationToken CancellationToken { get; } = cancellationToken;
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace ChengYuan.Core.Modularity;
2+
3+
public interface IModularApplication
4+
{
5+
IServiceProvider Services { get; }
6+
7+
IModuleCatalog ModuleCatalog { get; }
8+
9+
Task InitializeAsync(CancellationToken cancellationToken = default);
10+
11+
Task ShutdownAsync(CancellationToken cancellationToken = default);
12+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
3+
namespace ChengYuan.Core.Modularity;
4+
5+
public interface IModuleCatalog
6+
{
7+
IReadOnlyList<IModuleDescriptor> Modules { get; }
8+
9+
IReadOnlyList<Type> ModuleTypes { get; }
10+
11+
IModuleDescriptor GetModule(Type moduleType);
12+
13+
bool TryGetModule(Type moduleType, [NotNullWhen(true)] out IModuleDescriptor? descriptor);
14+
15+
bool IsLoaded<TModule>() where TModule : ModuleBase;
16+
17+
IReadOnlyList<IModuleDescriptor> GetInitializationOrder();
18+
19+
IReadOnlyList<IModuleDescriptor> GetShutdownOrder();
20+
}

0 commit comments

Comments
 (0)