• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ImmediatePlatform / Immediate.Jobs / 30724662640

02 Aug 2026 12:08AM UTC coverage: 83.991% (+0.09%) from 83.902%
30724662640

Pull #88

github

web-flow
Merge cab42b352 into 5a18eed93
Pull Request #88: Add `Immediate.Validations`

523 of 562 new or added lines in 36 files covered. (93.06%)

4 existing lines in 2 files now uncovered.

8242 of 9813 relevant lines covered (83.99%)

2.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.18
/src/Immediate.Jobs.Shared/ServiceCollectionExtensions.cs
1
using System.Diagnostics.CodeAnalysis;
2
using Immediate.Jobs.Shared.Apis;
3
using Immediate.Jobs.Shared.Interfaces;
4
using Immediate.Jobs.Shared.Internals;
5
using Immediate.Jobs.Shared.Storage;
6
using Microsoft.Extensions.DependencyInjection;
7
using Microsoft.Extensions.DependencyInjection.Extensions;
8
using Microsoft.Extensions.Diagnostics.HealthChecks;
9
using Microsoft.Extensions.Hosting;
10

11
namespace Immediate.Jobs.Shared;
12

13
/// <summary>
14
///         Runtime registration methods used by generated application extensions.
15
/// </summary>
16
public static class ImmediateJobsRuntimeServiceCollectionExtensions
17
{
18
        /// <summary>
19
        ///         Adds the scheduler runtime. Application code normally calls generated AddImmediateJobs instead.
20
        /// </summary>
21
        /// <param name="services">
22
        ///         The service collection to which the runtime is added.
23
        /// </param>
24
        /// <param name="configure">
25
        ///         An optional callback that configures the runtime.
26
        /// </param>
27
        /// <returns>
28
        ///         A builder for selecting storage and adding runtime integrations.
29
        /// </returns>
30
        public static ImmediateJobsBuilder AddImmediateJobsCore(
31
                this IServiceCollection services,
32
                Action<ImmediateJobsOptions>? configure = null
33
        )
34
        {
35
                ArgumentNullException.ThrowIfNull(services);
4✔
36

37
                var options = new ImmediateJobsOptions();
4✔
38
                configure?.Invoke(options);
4✔
39
                if (options.StorageFactory is null)
4✔
40
                {
41
                        if (options.StorageModeExplicitlySelected)
4✔
42
                                throw new ImmediateJobException("Select a durable storage provider before choosing single-server or distributed mode.");
4✔
43

44
                        _ = options.UseInMemory();
4✔
45
                }
46

47
                options.Validate();
4✔
48

49
                services.TryAddSingleton(options);
4✔
50
                services.TryAddSingleton(TimeProvider.System);
4✔
51
                services.TryAddSingleton<IIdGenerator>(GuidIdGenerator.Instance);
4✔
52
                services.TryAddSingleton<IJobSerializer, SystemTextJsonJobSerializer>();
4✔
53
                services.TryAddSingleton(options.CreateStorage);
4✔
54
                services.TryAddSingleton(static sp =>
4✔
55
                        sp.GetRequiredService<IJobStorage>() as IRecurringJobStorage
4✔
56
                                ?? null!);
4✔
57
                services.TryAddSingleton(static sp =>
4✔
58
                        sp.GetRequiredService<IJobStorage>() as IJobGraphStorage
4✔
59
                                ?? null!);
4✔
60
                services.TryAddScoped<BatchScheduler>();
4✔
61
                services.TryAddScoped<IBatchScheduler>(static sp =>
4✔
62
                        sp.GetService<IJobGraphStorage>() is null
4✔
63
                                ? null!
4✔
64
                                : sp.GetRequiredService<BatchScheduler>());
4✔
65
                services.TryAddScoped<JobMonitor>();
4✔
66
                services.TryAddScoped<IBatchMonitor>(static sp =>
4✔
67
                        sp.GetService<IJobGraphStorage>() is null
4✔
68
                                ? null!
4✔
69
                                : sp.GetRequiredService<JobMonitor>());
4✔
70
                services.TryAddScoped<IJobMonitor>(static sp =>
4✔
71
                        sp.GetRequiredService<JobMonitor>());
4✔
72
                _ = services.AddSingleton(JobQueueDefinition.Default);
4✔
73
                services.TryAddSingleton<JobSchedulerState>();
4✔
74
                services.TryAddSingleton<JobSchedulingService>();
4✔
75
                _ = services.AddSingleton<IHostedService>(
4✔
76
                        static sp => sp.GetRequiredService<JobSchedulingService>()
4✔
77
                );
4✔
78
                return new(services);
4✔
79
        }
80

81
        /// <summary>
82
        ///         Replaces the default GUID job and batch identifier generator.
83
        /// </summary>
84
        /// <typeparam name="TGenerator">
85
        ///         The identifier generator implementation.
86
        /// </typeparam>
87
        /// <param name="builder">
88
        ///         The Immediate.Jobs builder.
89
        /// </param>
90
        /// <returns>
91
        ///         The supplied builder.
92
        /// </returns>
93
        public static ImmediateJobsBuilder UseIdGenerator<
94
                [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TGenerator
95
        >(
96
                this ImmediateJobsBuilder builder
97
        )
98
                where TGenerator : class, IIdGenerator
99
        {
100
                ArgumentNullException.ThrowIfNull(builder);
4✔
101
                _ = builder.Services.Replace(ServiceDescriptor.Singleton<IIdGenerator, TGenerator>());
4✔
102
                return builder;
4✔
103
        }
104

105
        /// <summary>
106
        ///         Adds scheduler liveness and storage connectivity to the health-check system.
107
        /// </summary>
108
        /// <param name="builder">
109
        ///         The Immediate.Jobs builder.
110
        /// </param>
111
        /// <param name="name">
112
        ///         The registered health-check name.
113
        /// </param>
114
        /// <param name="failureStatus">
115
        ///         The status reported when the check fails.
116
        /// </param>
117
        /// <param name="tags">
118
        ///         The tags associated with the health check.
119
        /// </param>
120
        /// <returns>
121
        ///         The supplied builder.
122
        /// </returns>
123
        public static ImmediateJobsBuilder AddHealthCheck(
124
                this ImmediateJobsBuilder builder,
125
                string name = "immediate-jobs",
126
                HealthStatus? failureStatus = null,
127
                IEnumerable<string>? tags = null
128
        )
129
        {
130
                ArgumentNullException.ThrowIfNull(builder);
×
NEW
131
                _ = builder.Services.AddHealthChecks().AddCheck<ImmediateJobsHealthCheck>(name, failureStatus, tags ?? []);
×
132
                return builder;
×
133
        }
134
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc