Skip to content

Commit 78bf200

Browse files
stidsborgclaude
andauthored
Replace Options facade with ResilientFunctions Settings (#12)
* Replace Options facade with ResilientFunctions Settings Options was a 1:1 mirror of ResilientFunctions' Settings (with dead, never-called Merge methods), so every Settings API change forced a parallel Options edit. Drop it and use Settings directly. - Delete Cleipnir/Options.cs - FlowsContainer/FlowsModule: accept and store Settings; WithOptions now takes Settings; pass it straight to FunctionsRegistry - FlowOptions.Merge now takes Settings - Tests and samples: construct Settings instead of Options - README: fix InitialEffect example to use EffectId (0.ToEffectId()) Settings' internal properties are already visible to the Cleipnir and Cleipnir.Tests assemblies via InternalsVisibleTo in the submodule. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Make FlowsContainer settings parameter optional Default the settings parameter to null (falling back to new Settings()), so callers that don't customize settings can omit the argument entirely. Drop the now-redundant new Settings() at those call sites. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 1e1d57f commit 78bf200

26 files changed

Lines changed: 78 additions & 181 deletions

File tree

Cleipnir.Tests/Flows/FlowsWithResultTests.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ public async Task SimpleFlowCompletesSuccessfully()
1919
var flowStore = new InMemoryFunctionStore();
2020
var flowsContainer = new FlowsContainer(
2121
flowStore,
22-
serviceCollection.BuildServiceProvider(),
23-
Options.Default
22+
serviceCollection.BuildServiceProvider()
2423
);
2524

2625
var flows = new SimpleFuncFlows(flowsContainer);
@@ -67,7 +66,7 @@ public async Task CompletionOfScheduledFlowCanBeAwaited()
6766
var flowsContainer = new FlowsContainer(
6867
flowStore,
6968
serviceCollection.BuildServiceProvider(),
70-
new Options(watchdogCheckFrequency: TimeSpan.FromMilliseconds(100))
69+
new Settings(watchdogCheckFrequency: TimeSpan.FromMilliseconds(100))
7170
);
7271

7372
var flows = new SimpledDelayedFlows(flowsContainer);
@@ -104,7 +103,7 @@ public async Task EventDrivenFlowCompletesSuccessfully()
104103
var flowsContainer = new FlowsContainer(
105104
flowStore,
106105
serviceCollection.BuildServiceProvider(),
107-
new Options(watchdogCheckFrequency: TimeSpan.FromMilliseconds(100))
106+
new Settings(watchdogCheckFrequency: TimeSpan.FromMilliseconds(100))
108107
);
109108

110109
var flows = new MessageDrivenFuncFlows(flowsContainer);
@@ -151,8 +150,7 @@ public async Task FailingFlowCompletesWithError()
151150
var flowStore = new InMemoryFunctionStore();
152151
var flowsContainer = new FlowsContainer(
153152
flowStore,
154-
serviceCollection.BuildServiceProvider(),
155-
new Options()
153+
serviceCollection.BuildServiceProvider()
156154
);
157155

158156
var flows = new FailingFuncFlows(flowsContainer);

Cleipnir.Tests/Flows/MultipleRegistrationTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Cleipnir.ResilientFunctions.Storage;
2+
using Cleipnir.ResilientFunctions.Domain;
23
using Microsoft.Extensions.DependencyInjection;
34
using Shouldly;
45

@@ -12,7 +13,7 @@ public void SameFlowTypeWithSameNameCanBeRegisteredSeveralTimes()
1213
{
1314
var serviceCollection = new ServiceCollection();
1415
var store = new InMemoryFunctionStore();
15-
var flowsContainer = new FlowsContainer(store, serviceCollection.BuildServiceProvider(), new Options());
16+
var flowsContainer = new FlowsContainer(store, serviceCollection.BuildServiceProvider());
1617
_ = new TestFlowType1s(flowsContainer);
1718
_ = new TestFlowType1s(flowsContainer);
1819
}
@@ -22,7 +23,7 @@ public void DifferentFlowTypesWithSameNameCannotBeRegisteredSeveralTimes()
2223
{
2324
var serviceCollection = new ServiceCollection();
2425
var store = new InMemoryFunctionStore();
25-
var flowsContainer = new FlowsContainer(store, serviceCollection.BuildServiceProvider(), new Options());
26+
var flowsContainer = new FlowsContainer(store, serviceCollection.BuildServiceProvider());
2627
_ = new TestFlowType1s(flowsContainer);
2728
Should.Throw<InvalidOperationException>(() =>
2829
new TestFlowType2s(flowsContainer)

Cleipnir.Tests/Flows/OptionsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public async Task SimpleFlowCompletesSuccessfully()
1717

1818
serviceCollection.AddFlows(c => c
1919
.UseInMemoryStore()
20-
.WithOptions(new Options(
20+
.WithOptions(new Settings(
2121
messagesDefaultMaxWaitForCompletion: TimeSpan.FromDays(1),
2222
watchdogCheckFrequency: TimeSpan.FromMilliseconds(100)
2323
))
@@ -63,7 +63,7 @@ public async Task FlowNameCanBeSpecifiedFromTheOutside()
6363

6464
serviceCollection.AddFlows(c => c
6565
.UseInMemoryStore(store)
66-
.WithOptions(new Options(
66+
.WithOptions(new Settings(
6767
messagesDefaultMaxWaitForCompletion: TimeSpan.FromDays(1),
6868
watchdogCheckFrequency: TimeSpan.FromMilliseconds(100)
6969
))

Cleipnir.Tests/Flows/ParamlessFlowsTests.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ public async Task SimpleFlowCompletesSuccessfully()
1919
var flowStore = new InMemoryFunctionStore();
2020
var flowsContainer = new FlowsContainer(
2121
flowStore,
22-
serviceCollection.BuildServiceProvider(),
23-
Options.Default
22+
serviceCollection.BuildServiceProvider()
2423
);
2524

2625
var flows = new SimpleParamlessFlows(flowsContainer);
@@ -60,7 +59,7 @@ public async Task EventDrivenFlowCompletesSuccessfully()
6059
var flowsContainer = new FlowsContainer(
6160
flowStore,
6261
serviceCollection.BuildServiceProvider(),
63-
new Options(watchdogCheckFrequency: TimeSpan.FromMilliseconds(100))
62+
new Settings(watchdogCheckFrequency: TimeSpan.FromMilliseconds(100))
6463
);
6564

6665
var flows = new EventDrivenParamlessFlows(flowsContainer);
@@ -105,8 +104,7 @@ public async Task FailingFlowCompletesWithError()
105104
var flowStore = new InMemoryFunctionStore();
106105
var flowsContainer = new FlowsContainer(
107106
flowStore,
108-
serviceCollection.BuildServiceProvider(),
109-
new Options()
107+
serviceCollection.BuildServiceProvider()
110108
);
111109

112110
var flows = new FailingParamlessFlows(flowsContainer);

Cleipnir.Tests/Flows/UnitFlowsTests.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ public async Task SimpleFlowCompletesSuccessfully()
2020
var flowStore = new InMemoryFunctionStore();
2121
var flowsContainer = new FlowsContainer(
2222
flowStore,
23-
serviceCollection.BuildServiceProvider(),
24-
Options.Default
23+
serviceCollection.BuildServiceProvider()
2524
);
2625

2726
var flows = new SimpleUnitFlows(flowsContainer);
@@ -64,7 +63,7 @@ public async Task EventDrivenFlowCompletesSuccessfully()
6463
var flowsContainer = new FlowsContainer(
6564
flowStore,
6665
serviceCollection.BuildServiceProvider(),
67-
new Options(watchdogCheckFrequency: TimeSpan.FromMilliseconds(100))
66+
new Settings(watchdogCheckFrequency: TimeSpan.FromMilliseconds(100))
6867
);
6968

7069
var flows = new EventDrivenUnitFlows(flowsContainer);
@@ -110,8 +109,7 @@ public async Task FailingActionFlowCompletesWithError()
110109
var flowStore = new InMemoryFunctionStore();
111110
var flowsContainer = new FlowsContainer(
112111
flowStore,
113-
serviceCollection.BuildServiceProvider(),
114-
new Options()
112+
serviceCollection.BuildServiceProvider()
115113
);
116114

117115
var flows = new FallingUnitActionFlows(flowsContainer);
@@ -160,8 +158,7 @@ public async Task FailingFuncFlowCompletesWithError()
160158
var flowStore = new InMemoryFunctionStore();
161159
var flowsContainer = new FlowsContainer(
162160
flowStore,
163-
serviceCollection.BuildServiceProvider(),
164-
new Options()
161+
serviceCollection.BuildServiceProvider()
165162
);
166163

167164
var flows = new FallingUnitFuncFlows(flowsContainer);
@@ -210,8 +207,7 @@ public async Task FailingParamlessFlowCompletesWithError()
210207
var flowStore = new InMemoryFunctionStore();
211208
var flowsContainer = new FlowsContainer(
212209
flowStore,
213-
serviceCollection.BuildServiceProvider(),
214-
new Options()
210+
serviceCollection.BuildServiceProvider()
215211
);
216212

217213
var flows = new FailingUnitParamlessFlows(flowsContainer);

Cleipnir.Tests/Flows/UtcNowTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public async Task ProvidedUtcNowDelegateIsUsed()
1818
var flowsContainer = new FlowsContainer(
1919
new InMemoryFunctionStore(),
2020
serviceCollection.BuildServiceProvider(),
21-
new Options(utcNow: () => now, watchdogCheckFrequency: TimeSpan.FromMilliseconds(100))
21+
new Settings(utcNow: () => now, watchdogCheckFrequency: TimeSpan.FromMilliseconds(100))
2222
);
2323

2424
var flows = new Flows<UtcNowTestFlow, DateTime>(nameof(UtcNowTestFlow), flowsContainer);

Cleipnir/AspNet/FlowsModule.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static IServiceCollection AddFlows(this IServiceCollection services, Func
1717
configure(configurator);
1818

1919
if (configurator.OptionsFunc is null)
20-
services.AddSingleton(new Options());
20+
services.AddSingleton(new Settings());
2121
else
2222
services.AddSingleton(configurator.OptionsFunc);
2323

@@ -37,7 +37,7 @@ public class FlowsConfigurator(IServiceCollection services)
3737
internal bool EnableGracefulShutdown = false;
3838
internal readonly HashSet<Type> FlowsTypes = new();
3939

40-
internal Func<IServiceProvider, Options>? OptionsFunc;
40+
internal Func<IServiceProvider, Settings>? OptionsFunc;
4141
public IServiceCollection Services { get; } = services;
4242

4343
public FlowsConfigurator UseInMemoryStore(InMemoryFunctionStore? store = null)
@@ -52,10 +52,10 @@ public FlowsConfigurator UseStore(IFunctionStore store)
5252
return this;
5353
}
5454

55-
public FlowsConfigurator WithOptions(Options options)
56-
=> WithOptions(_ => options);
57-
58-
public FlowsConfigurator WithOptions(Func<IServiceProvider, Options> optionsFunc)
55+
public FlowsConfigurator WithOptions(Settings settings)
56+
=> WithOptions(_ => settings);
57+
58+
public FlowsConfigurator WithOptions(Func<IServiceProvider, Settings> optionsFunc)
5959
{
6060
OptionsFunc = optionsFunc;
6161
return this;

Cleipnir/FlowOptions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ public FlowOptions(
2525
MaxParallelRetryInvocations = maxParallelRetryInvocations;
2626
}
2727

28-
public FlowOptions Merge(Options options)
28+
public FlowOptions Merge(Settings settings)
2929
{
3030
return new FlowOptions(
31-
RetentionPeriod ?? options.RetentionPeriod,
32-
EnableWatchdogs ?? options.EnableWatchdogs,
33-
MessagesDefaultMaxWaitForCompletion ?? options.MessagesDefaultMaxWaitForCompletion,
34-
MaxParallelRetryInvocations ?? options.MaxParallelRetryInvocations
31+
RetentionPeriod ?? settings.RetentionPeriod,
32+
EnableWatchdogs ?? settings.EnableWatchdogs,
33+
MessagesDefaultMaxWaitForCompletion ?? settings.MessagesDefaultMaxWaitForCompletion,
34+
MaxParallelRetryInvocations ?? settings.MaxParallelRetryInvocations
3535
);
3636
}
3737

Cleipnir/FlowsContainer.cs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Threading;
44
using System.Threading.Tasks;
55
using Cleipnir.ResilientFunctions;
6+
using Cleipnir.ResilientFunctions.Domain;
67
using Cleipnir.ResilientFunctions.Storage;
78
using Microsoft.Extensions.DependencyInjection;
89
using Microsoft.Extensions.Logging;
@@ -18,30 +19,31 @@ public class FlowsContainer : IDisposable
1819

1920
public FunctionsRegistry Functions => FunctionRegistry;
2021

21-
public FlowsContainer(IFunctionStore flowStore, IServiceProvider serviceProvider, Options options)
22+
public FlowsContainer(IFunctionStore flowStore, IServiceProvider serviceProvider, Settings? settings = null)
2223
{
2324
ServiceProvider = serviceProvider;
25+
settings ??= new Settings();
2426

25-
if (options.UnhandledExceptionHandler == null && serviceProvider.GetService<ILogger>() != null)
27+
if (settings.UnhandledExceptionHandler == null && serviceProvider.GetService<ILogger>() != null)
2628
{
2729
var logger = serviceProvider.GetRequiredService<ILogger>();
28-
options = new Options(
30+
settings = new Settings(
2931
unhandledExceptionHandler: ex => logger.LogError(ex, "Unhandled exception in Cleipnir"),
30-
retentionPeriod: options.RetentionPeriod,
31-
retentionCleanUpFrequency: options.RetentionCleanUpFrequency,
32-
enableWatchdogs: options.EnableWatchdogs,
33-
watchdogCheckFrequency: options.WatchdogCheckFrequency,
34-
messagesPullFrequency: options.MessagesPullFrequency,
35-
messagesDefaultMaxWaitForCompletion: options.MessagesDefaultMaxWaitForCompletion,
36-
delayStartup: options.DelayStartup,
37-
maxParallelRetryInvocations: options.MaxParallelRetryInvocations,
38-
serializer: options.Serializer,
39-
utcNow: options.UtcNow,
40-
replicaHeartbeatFrequency: options.ReplicaHeartbeatFrequency
32+
retentionPeriod: settings.RetentionPeriod,
33+
retentionCleanUpFrequency: settings.RetentionCleanUpFrequency,
34+
enableWatchdogs: settings.EnableWatchdogs,
35+
watchdogCheckFrequency: settings.WatchdogCheckFrequency,
36+
messagesPullFrequency: settings.MessagesPullFrequency,
37+
messagesDefaultMaxWaitForCompletion: settings.MessagesDefaultMaxWaitForCompletion,
38+
delayStartup: settings.DelayStartup,
39+
maxParallelRetryInvocations: settings.MaxParallelRetryInvocations,
40+
serializer: settings.Serializer,
41+
utcNow: settings.UtcNow,
42+
replicaHeartbeatFrequency: settings.ReplicaHeartbeatFrequency
4143
);
4244
}
4345

44-
FunctionRegistry = new FunctionsRegistry(flowStore, options.MapToSettings());
46+
FunctionRegistry = new FunctionsRegistry(flowStore, settings);
4547
}
4648

4749
internal void EnsureNoExistingRegistration(string flowName, Type flowType)
@@ -77,10 +79,10 @@ public Flows<TFlow, TParam, TResult> RegisterAnonymousFlow<TFlow, TParam, TResul
7779
public static FlowsContainer Create(
7880
IServiceProvider? serviceProvider = null,
7981
IFunctionStore? functionStore = null,
80-
Options? options = null)
82+
Settings? settings = null)
8183
=> new(
8284
functionStore ?? new InMemoryFunctionStore(),
8385
serviceProvider ?? new ServiceCollection().BuildServiceProvider(),
84-
options ?? Options.Default
86+
settings ?? new Settings()
8587
);
8688
}

Cleipnir/Options.cs

Lines changed: 0 additions & 103 deletions
This file was deleted.

0 commit comments

Comments
 (0)