Skip to content

Commit c563853

Browse files
committed
Fix: Code Cleanup
1 parent f3bacd8 commit c563853

File tree

14 files changed

+151
-135
lines changed

14 files changed

+151
-135
lines changed

src/CodeOfChaos.Types.DataSeeder/CodeOfChaos.Types.DataSeeder.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@
2323
</PropertyGroup>
2424

2525
<ItemGroup Label="InternalsVisibleTo">
26-
<InternalsVisibleTo Include="Tests.CodeOfChaos.Types.DataSeeder" />
27-
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
26+
<InternalsVisibleTo Include="Tests.CodeOfChaos.Types.DataSeeder"/>
27+
<InternalsVisibleTo Include="DynamicProxyGenAssembly2"/>
2828
</ItemGroup>
2929

3030
<ItemGroup>
31-
<None Include="../../LICENSE" Pack="true" PackagePath="" Visible="false" />
32-
<None Include="../../README.md" Pack="true" PackagePath="" Visible="false" />
33-
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false" />
31+
<None Include="../../LICENSE" Pack="true" PackagePath="" Visible="false"/>
32+
<None Include="../../README.md" Pack="true" PackagePath="" Visible="false"/>
33+
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false"/>
3434
</ItemGroup>
3535

3636
<ItemGroup>
37-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
38-
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.0" />
37+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0"/>
38+
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.0"/>
3939
</ItemGroup>
4040

4141
</Project>

src/CodeOfChaos.Types.DataSeeder/IDataSeeder.cs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,55 +10,56 @@ namespace CodeOfChaos.Types;
1010
// ---------------------------------------------------------------------------------------------------------------------
1111
public interface IDataSeederService : IHostedService {
1212
/// <summary>
13-
/// Adds a seeder of type TSeeder to the data seeder service.
14-
/// TSeeder must implement the ISeeder interface.
13+
/// Adds a seeder of type TSeeder to the data seeder service.
14+
/// TSeeder must implement the ISeeder interface.
1515
/// </summary>
1616
/// <typeparam name="TSeeder">The type of the seeder to be added.</typeparam>
1717
/// <returns>An instance of IDataSeederService to allow method chaining.</returns>
1818
IDataSeederService AddSeeder<TSeeder>() where TSeeder : ISeeder;
19-
19+
2020
/// <summary>
21-
/// Adds a group of seeders to the seeder service using the specified <paramref name="group"/> configuration callback.
21+
/// Adds a group of seeders to the seeder service using the specified <paramref name="group" /> configuration callback.
2222
/// </summary>
2323
/// <param name="group">
24-
/// An action that allows configuration of the <see cref="SeederGroup"/> by adding individual seeders.
24+
/// An action that allows configuration of the <see cref="SeederGroup" /> by adding individual seeders.
2525
/// </param>
2626
/// <returns>
27-
/// The updated instance of <see cref="IDataSeederService"/> to allow method chaining.
27+
/// The updated instance of <see cref="IDataSeederService" /> to allow method chaining.
2828
/// </returns>
2929
IDataSeederService AddSeederGroup(Action<SeederGroup> group);
30-
30+
3131
/// <summary>
32-
/// Adds a group of seeders to the current seeder service.
32+
/// Adds a group of seeders to the current seeder service.
3333
/// </summary>
3434
/// <param name="group">
35-
/// An instance of <see cref="SeederGroup"/> containing the seeders to be added.
35+
/// An instance of <see cref="SeederGroup" /> containing the seeders to be added.
3636
/// </param>
3737
/// <returns>
38-
/// The current instance of <see cref="IDataSeederService"/> with the added seeder group.
38+
/// The current instance of <see cref="IDataSeederService" /> with the added seeder group.
3939
/// </returns>
4040
IDataSeederService AddSeederGroup(SeederGroup group);
41-
41+
4242
/// <summary>
43-
/// Adds remaining seeder types from the provided assembly to the data seeder service.
44-
/// Ensures that only non-abstract, non-generic, and non-interface types implementing the <see cref="ISeeder"/> interface are added.
43+
/// Adds remaining seeder types from the provided assembly to the data seeder service.
44+
/// Ensures that only non-abstract, non-generic, and non-interface types implementing the <see cref="ISeeder" />
45+
/// interface are added.
4546
/// </summary>
4647
/// <param name="assembly">
47-
/// The assembly from which seeder types will be collected.
48+
/// The assembly from which seeder types will be collected.
4849
/// </param>
4950
/// <exception cref="AggregateException">
50-
/// Thrown when one or more seeder types fail to be instantiated.
51+
/// Thrown when one or more seeder types fail to be instantiated.
5152
/// </exception>
5253
void AddRemainderSeeders(Assembly assembly);
53-
54+
5455
/// <summary>
55-
/// Adds all unprocessed data seeder types from the provided assembly as a single group to be executed together.
56+
/// Adds all unprocessed data seeder types from the provided assembly as a single group to be executed together.
5657
/// </summary>
5758
/// <param name="assembly">
58-
/// The assembly from which to collect remaining data seeder types.
59+
/// The assembly from which to collect remaining data seeder types.
5960
/// </param>
6061
/// <exception cref="AggregateException">
61-
/// Thrown if there are multiple errors while adding seeders to the group.
62+
/// Thrown if there are multiple errors while adding seeders to the group.
6263
/// </exception>
6364
void AddRemainderSeedersAsOneGroup(Assembly assembly);
6465
}

src/CodeOfChaos.Types.DataSeeder/ISeeder.cs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,39 @@ namespace CodeOfChaos.Types;
88
// Code
99
// ---------------------------------------------------------------------------------------------------------------------
1010
/// <summary>
11-
/// Defines a contract for a seeding mechanism that determines whether a seed process should run
12-
/// and executes the seeding logic if required.
11+
/// Defines a contract for a seeding mechanism that determines whether a seed process should run
12+
/// and executes the seeding logic if required.
1313
/// </summary>
1414
public interface ISeeder {
1515
/// <summary>
16-
/// Initiates the seeding process for the implementing class.
16+
/// Initiates the seeding process for the implementing class.
1717
/// </summary>
18-
/// <param name="logger">An instance of <see cref="ILogger"/> for logging operations.</param>
19-
/// <param name="ct">A <see cref="CancellationToken"/> to observe while waiting for the task to complete. Defaults to <see cref="CancellationToken.None"/>.</param>
20-
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
18+
/// <param name="logger">An instance of <see cref="ILogger" /> for logging operations.</param>
19+
/// <param name="ct">
20+
/// A <see cref="CancellationToken" /> to observe while waiting for the task to complete. Defaults to
21+
/// <see cref="CancellationToken.None" />.
22+
/// </param>
23+
/// <returns>A <see cref="Task" /> that represents the asynchronous operation.</returns>
2124
/// <remarks>
22-
/// This method should first checks whether seeding should occur by calling <c>ShouldSeedAsync</c>. If seeding is not needed, it logs an informational message and returns.
23-
/// If seeding is required, the method executes <c>SeedAsync</c>, respecting the provided cancellation token.
25+
/// This method should first checks whether seeding should occur by calling <c>ShouldSeedAsync</c>. If seeding is not
26+
/// needed, it logs an informational message and returns.
27+
/// If seeding is required, the method executes <c>SeedAsync</c>, respecting the provided cancellation token.
2428
/// </remarks>
2529
Task StartAsync(ILogger logger, CancellationToken ct = default);
26-
30+
2731
/// Determines whether the seeding process should proceed or be skipped.
2832
/// <param name="ct">A cancellation token that can be used to cancel the operation.</param>
29-
/// <return>A task representing the asynchronous operation. The task result contains a boolean indicating
30-
/// whether the seeding process should proceed (true) or be skipped (false).</return>
33+
/// <return>
34+
/// A task representing the asynchronous operation. The task result contains a boolean indicating
35+
/// whether the seeding process should proceed (true) or be skipped (false).
36+
/// </return>
3137
Task<bool> ShouldSeedAsync(CancellationToken ct = default);
32-
38+
3339
/// <summary>
34-
/// Executes the seed operation for a data seeder. This method is intended to be overridden
35-
/// by derived classes to implement data seeding logic.
40+
/// Executes the seed operation for a data seeder. This method is intended to be overridden
41+
/// by derived classes to implement data seeding logic.
3642
/// </summary>
37-
/// <param name="ct">The <see cref="CancellationToken"/> that can be used to signal a request to cancel the operation.</param>
43+
/// <param name="ct">The <see cref="CancellationToken" /> that can be used to signal a request to cancel the operation.</param>
3844
/// <returns>A task that represents the asynchronous operation.</returns>
3945
Task SeedAsync(CancellationToken ct = default);
4046
}

src/CodeOfChaos.Types.DataSeeder/OneTimeDataSeederService.cs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,44 @@ namespace CodeOfChaos.Types;
1212
// ---------------------------------------------------------------------------------------------------------------------
1313
public class OneTimeDataSeederService(IServiceProvider serviceProvider, ILogger<OneTimeDataSeederService> logger) : IDataSeederService {
1414
/// <summary>
15-
/// Represents a thread-safe queue of SeederGroup objects used within the OneTimeDataSeederService
16-
/// to maintain and manage seeding operations.
15+
/// Represents a thread-safe queue of SeederGroup objects used within the OneTimeDataSeederService
16+
/// to maintain and manage seeding operations.
1717
/// </summary>
1818
/// <remarks>
19-
/// The <c>Seeders</c> field serves as the central storage for SeederGroups, allowing them to be
20-
/// enqueued and dequeued in a controlled manner during the seeding process. This ensures
21-
/// proper execution order and thread safety for concurrent operations.
19+
/// The <c>Seeders</c> field serves as the central storage for SeederGroups, allowing them to be
20+
/// enqueued and dequeued in a controlled manner during the seeding process. This ensures
21+
/// proper execution order and thread safety for concurrent operations.
2222
/// </remarks>
2323
protected readonly ConcurrentQueue<SeederGroup> Seeders = [];
24-
24+
2525
/// <summary>
26-
/// Represents a thread-safe collection of seeder types used by the OneTimeDataSeederService to track
27-
/// registered data seeders. This collection ensures that each type of seeder is only added once
28-
/// and prevents duplicates during the seeding process. It plays a critical role in managing
29-
/// and validating the lifecycle of seeders added to the service.
26+
/// Represents a thread-safe collection of seeder types used by the OneTimeDataSeederService to track
27+
/// registered data seeders. This collection ensures that each type of seeder is only added once
28+
/// and prevents duplicates during the seeding process. It plays a critical role in managing
29+
/// and validating the lifecycle of seeders added to the service.
3030
/// </summary>
3131
protected readonly ConcurrentBag<Type> SeederTypes = [];
32-
32+
3333
/// <summary>
34-
/// Indicates whether the remainder seeders have been successfully collected.
35-
/// If set to <c>true</c>, it indicates that no additional remainder seeders can
36-
/// be added to the service, and attempting to do so will throw an exception.
34+
/// Indicates whether the remainder seeders have been successfully collected.
35+
/// If set to <c>true</c>, it indicates that no additional remainder seeders can
36+
/// be added to the service, and attempting to do so will throw an exception.
3737
/// </summary>
3838
protected bool CollectedRemainders;// If set to true, the remainder seeders have been collected and thus should throw an exception if any are added
3939

4040
// -----------------------------------------------------------------------------------------------------------------
4141
// Methods
4242
// -----------------------------------------------------------------------------------------------------------------
4343
/// <summary>
44-
/// Starts the data seeding process by executing all configured seeder groups in sequence.
45-
/// Validates seeders, collects data, and manages the lifecycle of each group using scoped services.
44+
/// Starts the data seeding process by executing all configured seeder groups in sequence.
45+
/// Validates seeders, collects data, and manages the lifecycle of each group using scoped services.
4646
/// </summary>
4747
/// <param name="ct">A CancellationToken used to observe cancellation requests.</param>
4848
/// <returns>A Task representing the asynchronous operation.</returns>
4949
public async Task StartAsync(CancellationToken ct = default) {
5050
logger.LogInformation("DataSeederService starting...");
51-
52-
await CollectAsync(ct); // If user choose the old format of adding seeders, this will be what ads the seeders to the queue
51+
52+
await CollectAsync(ct);// If user choose the old format of adding seeders, this will be what ads the seeders to the queue
5353
ct.ThrowIfCancellationRequested();// Don't throw during collection, but throw afterward
5454

5555
// Validation has to succeed before we continue
@@ -70,16 +70,16 @@ public async Task StartAsync(CancellationToken ct = default) {
7070
}
7171

7272
// Each group should have their own scope
73-
await using AsyncServiceScope scope = serviceProvider.CreateAsyncScope();
73+
await using AsyncServiceScope scope = serviceProvider.CreateAsyncScope();
7474
IServiceProvider scopeProvider = scope.ServiceProvider;
7575
List<ISeeder> seeders = [];
76-
76+
7777
while (seederGroup.SeederTypes.TryDequeue(out Type? seederType)) {
7878
var seeder = (ISeeder)scopeProvider.GetRequiredService(seederType);
7979
seeders.Add(seeder);
80-
80+
8181
}
82-
82+
8383
logger.LogDebug("ExecutionStep {step} : {count} Seeder(s) found, executing...", i++, seeders.Count);
8484
await Task.WhenAll(seeders.Select(seeder => seeder.StartAsync(logger, ct)));
8585
}
@@ -92,7 +92,7 @@ public async Task StartAsync(CancellationToken ct = default) {
9292
}
9393

9494
/// <summary>
95-
/// Asynchronously stops the OneTimeDataSeederService, handling any necessary cleanup or finalization logic.
95+
/// Asynchronously stops the OneTimeDataSeederService, handling any necessary cleanup or finalization logic.
9696
/// </summary>
9797
/// <param name="ct">The cancellation token to observe while awaiting the task to complete.</param>
9898
/// <returns>A task that completes when the service has been stopped.</returns>
@@ -101,14 +101,6 @@ public Task StopAsync(CancellationToken ct = default) {
101101
return Task.CompletedTask;
102102
}
103103

104-
/// <summary>
105-
/// Collects seeders asynchronously to prepare for execution based on the seeding logic.
106-
/// This method is intended to be overridden for custom collection logic.
107-
/// </summary>
108-
/// <param name="ct">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
109-
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
110-
protected virtual Task CollectAsync(CancellationToken ct = default) => Task.CompletedTask;
111-
112104
// -----------------------------------------------------------------------------------------------------------------
113105
// Seeder manipulation Methods
114106
// -----------------------------------------------------------------------------------------------------------------
@@ -122,7 +114,7 @@ public IDataSeederService AddSeederGroup(Action<SeederGroup> group) {
122114
group(seeders);
123115
return AddSeederGroup(seeders);
124116
}
125-
117+
126118
/// <inheritdoc />
127119
public IDataSeederService AddSeederGroup(SeederGroup group) {
128120
ThrowIfRemainderSeeders();
@@ -134,7 +126,7 @@ public IDataSeederService AddSeederGroup(SeederGroup group) {
134126

135127
return this;
136128
}
137-
129+
138130
/// <inheritdoc />
139131
public void AddRemainderSeeders(Assembly assembly) {
140132
Type[] types = CollectTypes(assembly);
@@ -159,7 +151,7 @@ public void AddRemainderSeeders(Assembly assembly) {
159151

160152
CollectedRemainders = true;
161153
}
162-
154+
163155
/// <inheritdoc />
164156
public void AddRemainderSeedersAsOneGroup(Assembly assembly) {
165157
Type[] types = CollectTypes(assembly);
@@ -189,6 +181,14 @@ public void AddRemainderSeedersAsOneGroup(Assembly assembly) {
189181
CollectedRemainders = true;
190182
}
191183

184+
/// <summary>
185+
/// Collects seeders asynchronously to prepare for execution based on the seeding logic.
186+
/// This method is intended to be overridden for custom collection logic.
187+
/// </summary>
188+
/// <param name="ct">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
189+
/// <returns>A <see cref="Task" /> representing the asynchronous operation.</returns>
190+
protected virtual Task CollectAsync(CancellationToken ct = default) => Task.CompletedTask;
191+
192192
private static Type[] CollectTypes(Assembly assembly)
193193
=> assembly.GetTypes()
194194
// order is deterministic

src/CodeOfChaos.Types.DataSeeder/Seeder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ namespace CodeOfChaos.Types;
88
// Code
99
// ---------------------------------------------------------------------------------------------------------------------
1010
/// <summary>
11-
/// Represents an abstract implementation of the <see cref="ISeeder"/> interface, providing
12-
/// a base class for seeding operations with pre-seeding validation logic.
11+
/// Represents an abstract implementation of the <see cref="ISeeder" /> interface, providing
12+
/// a base class for seeding operations with pre-seeding validation logic.
1313
/// </summary>
1414
public abstract class Seeder : ISeeder {
1515
/// <inheritdoc />
@@ -25,7 +25,7 @@ public async Task StartAsync(ILogger logger, CancellationToken ct = default) {
2525

2626
/// <inheritdoc />
2727
public virtual Task<bool> ShouldSeedAsync(CancellationToken ct = default) => Task.FromResult(true);
28-
28+
2929
/// <inheritdoc />
3030
public abstract Task SeedAsync(CancellationToken ct = default);
3131
}

0 commit comments

Comments
 (0)