Adding Foundatio builders for configuring in IServiceCollection. Various other improvements.#393
Conversation
…ous other improvements.
There was a problem hiding this comment.
Pull Request Overview
This PR enhances Foundatio’s configuration and extensibility by introducing fluent builder APIs, integrating resilience policies, refining startup actions, and adding utilities for replacing singleton services.
- Adds
FoundatioBuilderextensions for configuring caching, storage, messaging, locking, resilience, and serialization viaIServiceCollection. - Integrates
IResiliencePolicyProviderintoSample1Joband refactorsResiliencePolicyProviderdefaults and builder methods. - Refactors
SystemTextJsonSerializerto support customJsonSerializerOptionsand updates related tests. - Updates startup action extension methods to return
IServiceCollectionfor improved chaining.
Reviewed Changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/Foundatio.Tests/Serializer/SystemTextJsonSerializerTests.cs | Added option-based serializer tests and a benchmark stub. |
| src/Foundatio/Serializer/SystemTextJsonSerializer.cs | Refactored default serialization/deserialization option logic. |
| src/Foundatio/Resilience/ResiliencePolicyProvider.cs | Changed default policy initialization and optional builders. |
| samples/Foundatio.HostingSample/Program.cs | Updated sample to use FoundatioBuilder and resilience APIs. |
Comments suppressed due to low confidence (3)
src/Foundatio/Resilience/ResiliencePolicyProvider.cs:24
- The default policy no longer sets a non-zero
MaxAttempts(previously 5), changing retry behavior. Consider restoringMaxAttempts = 5or making it configurable to avoid unexpected single-attempt defaults.
_defaultPolicy = new ResiliencePolicy(_loggerFactory.CreateLogger<ResiliencePolicy>(), _timeProvider);
samples/Foundatio.HostingSample/Program.cs:218
- [nitpick] This second
AddFoundatio()call insideConfigureServicesduplicates the builder registration from the top ofProgram.cs. Consider reusing the existingFoundatioBuilderinstance instead of registering twice.
builder.Services.AddFoundatio()
src/Foundatio/Serializer/SystemTextJsonSerializer.cs:18
- [nitpick] Falling back to
serializeOptionsfor deserialization may omit converters (e.g., type-inference logic). Consider always merging user-supplied options with_defaultDeserializeOptionsto preserve required converters.
_deserializeOptions = deserializeOptions ?? serializeOptions ?? _defaultDeserializeOptions;
tests/Foundatio.Tests/Serializer/SystemTextJsonSerializerTests.cs
Outdated
Show resolved
Hide resolved
|
One question that I had is if you call AddQueueing(s => s.AddResilency(...options)) And then you could also override it like this. AddQueueing().UseAzureStorageQueue().UseSQSQueue(f => f.AddResilency(...options)) (example would work better on repos or queues. qon |
|
I don't know what you are asking. Yes, we currently have a few different ways to configure things. This PR is trying to reduce those with the builders. |
This pull request introduces resilience policies into the
Sample1Job, enhances service configuration in the hosting sample, refines startup action methods, and adds utility methods for replacing singleton services. The changes improve job reliability, simplify service management, and enhance extensibility.Resilience and Job Enhancements:
samples/Foundatio.HostingSample/Jobs/Sample1Job.cs: Integrated resilience policies usingIResiliencePolicyto handle retries and simulate failures inSample1Job. This ensures the job can recover from transient errors.Service Configuration Improvements:
samples/Foundatio.HostingSample/Program.cs: Added Foundatio services configuration to streamline caching, messaging, locking, and resilience policies. Redis is used for distributed caching and messaging, replacing in-memory implementations. [1] [2]Startup Action Refinements:
src/Foundatio.Extensions.Hosting/Startup/StartupExtensions.cs: UpdatedAddStartupActionmethods to returnIServiceCollection, improving method chaining and consistency. Added null-coalescing assignments for health check tags and predicates to simplify code. [1] [2] [3] [4]Utility Methods for Service Replacement:
src/Foundatio/Extensions/ServicesExtensions.cs: IntroducedReplaceSingletonmethods to replace existing service descriptors with new singleton services, enhancing service configurability.Minor Fixes:
src/Foundatio.TestHarness/Jobs/JobQueueTestsBase.csandsrc/Foundatio.TestHarness/Jobs/ThrottledJob.cs: Removed redundant parameters inThrottlingLockProviderinstantiation, simplifying code. [1] [2]