Skip to content

Commit a00f7f2

Browse files
committed
Flow extension methods simplification
1 parent f632f50 commit a00f7f2

2 files changed

Lines changed: 7 additions & 23 deletions

File tree

Cleipnir.Flows/AspNet/FlowsHostedService.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,22 @@
77

88
namespace Cleipnir.Flows.AspNet;
99

10-
public class FlowsHostedService : IHostedService
10+
public class FlowsHostedService(IServiceProvider services, IEnumerable<Type> flowsTypes, bool gracefulShutdown) : IHostedService
1111
{
12-
private readonly IServiceProvider _services;
13-
private readonly IEnumerable<Type> _flowsTypes;
14-
private readonly bool _gracefulShutdown;
15-
16-
public FlowsHostedService(IServiceProvider services, IEnumerable<Type> flowsTypes, bool gracefulShutdown)
17-
{
18-
_services = services;
19-
_flowsTypes = flowsTypes;
20-
_gracefulShutdown = gracefulShutdown;
21-
}
22-
2312
public Task StartAsync(CancellationToken cancellationToken)
2413
{
25-
foreach (var flowsType in _flowsTypes)
26-
_ = _services.GetService(flowsType); //flow is registered with the flow container when resolved
14+
foreach (var flowsType in flowsTypes)
15+
_ = services.GetService(flowsType); //flow is registered with the flow container when resolved
2716

2817
return Task.CompletedTask;
2918
}
3019

3120
public Task StopAsync(CancellationToken cancellationToken)
3221
{
33-
var flowsContainer = _services.GetRequiredService<FlowsContainer>();
22+
var flowsContainer = services.GetRequiredService<FlowsContainer>();
3423

3524
var shutdownTask = flowsContainer.ShutdownGracefully();
36-
return _gracefulShutdown
25+
return gracefulShutdown
3726
? shutdownTask
3827
: Task.CompletedTask;
3928
}

Cleipnir.Flows/AspNet/FlowsModule.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,13 @@ public static IServiceCollection AddFlows(this IServiceCollection services, Func
3232
}
3333
}
3434

35-
public class FlowsConfigurator
35+
public class FlowsConfigurator(IServiceCollection services)
3636
{
3737
internal bool EnableGracefulShutdown = false;
3838
internal readonly HashSet<Type> FlowsTypes = new();
3939

4040
internal Func<IServiceProvider, Options>? OptionsFunc;
41-
public IServiceCollection Services { get; }
42-
43-
public FlowsConfigurator(IServiceCollection services)
44-
{
45-
Services = services;
46-
}
41+
public IServiceCollection Services { get; } = services;
4742

4843
public FlowsConfigurator UseInMemoryStore(InMemoryFunctionStore? store = null)
4944
{

0 commit comments

Comments
 (0)