Skip to content

Commit b72cd47

Browse files
committed
review
1 parent 338378a commit b72cd47

File tree

3 files changed

+47
-26
lines changed

3 files changed

+47
-26
lines changed

Eocron.DependencyInjection/DecoratorExtensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,12 @@ private static ServiceDescriptor CloneWithNewKey(ServiceDescriptor descriptor)
9191
}
9292
return new ServiceDescriptor(descriptor.ServiceType, newKey, descriptor.ImplementationType, descriptor.Lifetime);
9393
}
94+
95+
private static DecoratorChain ToChain(Action<DecoratorChain> chainBuilder)
96+
{
97+
var chain = new DecoratorChain();
98+
chainBuilder(chain);
99+
return chain;
100+
}
94101
}
95102
}

Eocron.DependencyInjection/KeyedServiceCollectionExtensions.cs

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Eocron.DependencyInjection
66
{
7-
public static partial class ServiceCollectionServiceExtensions
7+
public static partial class ServiceCollectionServiceExtensions
88
{
99
/// <summary>
1010
/// Adds a transient service of the type specified in <paramref name="serviceType"/> with an
@@ -21,10 +21,12 @@ public static IServiceCollection AddKeyedTransient(
2121
this IServiceCollection services,
2222
Type serviceType,
2323
object? serviceKey,
24-
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type implementationType,
24+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
25+
Type implementationType,
2526
Action<DecoratorChain> chainBuilder)
2627
{
27-
return AddKeyed(services, serviceType, serviceKey, implementationType, ServiceLifetime.Transient, chainBuilder);
28+
return AddKeyed(services, serviceType, serviceKey, implementationType, ServiceLifetime.Transient,
29+
chainBuilder);
2830
}
2931

3032
/// <summary>
@@ -45,7 +47,8 @@ public static IServiceCollection AddKeyedTransient(
4547
Func<IServiceProvider, object?, object> implementationFactory,
4648
Action<DecoratorChain> chainBuilder)
4749
{
48-
return AddKeyed(services, serviceType, serviceKey, implementationFactory, ServiceLifetime.Transient, chainBuilder);
50+
return AddKeyed(services, serviceType, serviceKey, implementationFactory, ServiceLifetime.Transient,
51+
chainBuilder);
4952
}
5053

5154
/// <summary>
@@ -59,7 +62,8 @@ public static IServiceCollection AddKeyedTransient(
5962
/// <param name="serviceKey">The <see cref="ServiceDescriptor.ServiceKey"/> of the service.</param>
6063
/// <returns>A reference to this instance after the operation has completed.</returns>
6164
/// <seealso cref="ServiceLifetime.Transient"/>
62-
public static IServiceCollection AddKeyedTransient<TService, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TImplementation>(
65+
public static IServiceCollection AddKeyedTransient<TService,
66+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TImplementation>(
6367
this IServiceCollection services,
6468
object? serviceKey,
6569
Action<DecoratorChain> chainBuilder)
@@ -80,7 +84,8 @@ public static IServiceCollection AddKeyedTransient(
8084
/// <seealso cref="ServiceLifetime.Transient"/>
8185
public static IServiceCollection AddKeyedTransient(
8286
this IServiceCollection services,
83-
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type serviceType,
87+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
88+
Type serviceType,
8489
object? serviceKey,
8590
Action<DecoratorChain> chainBuilder)
8691
{
@@ -96,7 +101,8 @@ public static IServiceCollection AddKeyedTransient(
96101
/// <param name="serviceKey">The <see cref="ServiceDescriptor.ServiceKey"/> of the service.</param>
97102
/// <returns>A reference to this instance after the operation has completed.</returns>
98103
/// <seealso cref="ServiceLifetime.Transient"/>
99-
public static IServiceCollection AddKeyedTransient<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TService>(
104+
public static IServiceCollection AddKeyedTransient<
105+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TService>(
100106
this IServiceCollection services,
101107
object? serviceKey,
102108
Action<DecoratorChain> chainBuilder)
@@ -165,10 +171,12 @@ public static IServiceCollection AddKeyedScoped(
165171
this IServiceCollection services,
166172
Type serviceType,
167173
object? serviceKey,
168-
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type implementationType,
174+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
175+
Type implementationType,
169176
Action<DecoratorChain> chainBuilder)
170177
{
171-
return AddKeyed(services, serviceType, serviceKey, implementationType, ServiceLifetime.Scoped, chainBuilder);
178+
return AddKeyed(services, serviceType, serviceKey, implementationType, ServiceLifetime.Scoped,
179+
chainBuilder);
172180
}
173181

174182
/// <summary>
@@ -189,7 +197,8 @@ public static IServiceCollection AddKeyedScoped(
189197
Func<IServiceProvider, object?, object> implementationFactory,
190198
Action<DecoratorChain> chainBuilder)
191199
{
192-
return AddKeyed(services, serviceType, serviceKey, implementationFactory, ServiceLifetime.Scoped, chainBuilder);
200+
return AddKeyed(services, serviceType, serviceKey, implementationFactory, ServiceLifetime.Scoped,
201+
chainBuilder);
193202
}
194203

195204
/// <summary>
@@ -203,7 +212,8 @@ public static IServiceCollection AddKeyedScoped(
203212
/// <param name="serviceKey">The <see cref="ServiceDescriptor.ServiceKey"/> of the service.</param>
204213
/// <returns>A reference to this instance after the operation has completed.</returns>
205214
/// <seealso cref="ServiceLifetime.Scoped"/>
206-
public static IServiceCollection AddKeyedScoped<TService, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TImplementation>(
215+
public static IServiceCollection AddKeyedScoped<TService,
216+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TImplementation>(
207217
this IServiceCollection services,
208218
object? serviceKey,
209219
Action<DecoratorChain> chainBuilder)
@@ -224,7 +234,8 @@ public static IServiceCollection AddKeyedScoped(
224234
/// <seealso cref="ServiceLifetime.Scoped"/>
225235
public static IServiceCollection AddKeyedScoped(
226236
this IServiceCollection services,
227-
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type serviceType,
237+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
238+
Type serviceType,
228239
object? serviceKey,
229240
Action<DecoratorChain> chainBuilder)
230241
{
@@ -240,7 +251,8 @@ public static IServiceCollection AddKeyedScoped(
240251
/// <param name="serviceKey">The <see cref="ServiceDescriptor.ServiceKey"/> of the service.</param>
241252
/// <returns>A reference to this instance after the operation has completed.</returns>
242253
/// <seealso cref="ServiceLifetime.Scoped"/>
243-
public static IServiceCollection AddKeyedScoped<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TService>(
254+
public static IServiceCollection AddKeyedScoped<
255+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TService>(
244256
this IServiceCollection services,
245257
object? serviceKey,
246258
Action<DecoratorChain> chainBuilder)
@@ -310,10 +322,12 @@ public static IServiceCollection AddKeyedSingleton(
310322
this IServiceCollection services,
311323
Type serviceType,
312324
object? serviceKey,
313-
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type implementationType,
325+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
326+
Type implementationType,
314327
Action<DecoratorChain> chainBuilder)
315328
{
316-
return AddKeyed(services, serviceType, serviceKey, implementationType, ServiceLifetime.Singleton, chainBuilder);
329+
return AddKeyed(services, serviceType, serviceKey, implementationType, ServiceLifetime.Singleton,
330+
chainBuilder);
317331
}
318332

319333
/// <summary>
@@ -334,7 +348,8 @@ public static IServiceCollection AddKeyedSingleton(
334348
Func<IServiceProvider, object?, object> implementationFactory,
335349
Action<DecoratorChain> chainBuilder)
336350
{
337-
return AddKeyed(services, serviceType, serviceKey, implementationFactory, ServiceLifetime.Singleton, chainBuilder);
351+
return AddKeyed(services, serviceType, serviceKey, implementationFactory, ServiceLifetime.Singleton,
352+
chainBuilder);
338353
}
339354

340355
/// <summary>
@@ -348,7 +363,8 @@ public static IServiceCollection AddKeyedSingleton(
348363
/// <param name="serviceKey">The <see cref="ServiceDescriptor.ServiceKey"/> of the service.</param>
349364
/// <returns>A reference to this instance after the operation has completed.</returns>
350365
/// <seealso cref="ServiceLifetime.Singleton"/>
351-
public static IServiceCollection AddKeyedSingleton<TService, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TImplementation>(
366+
public static IServiceCollection AddKeyedSingleton<TService,
367+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TImplementation>(
352368
this IServiceCollection services,
353369
object? serviceKey,
354370
Action<DecoratorChain> chainBuilder)
@@ -369,7 +385,8 @@ public static IServiceCollection AddKeyedSingleton(
369385
/// <seealso cref="ServiceLifetime.Singleton"/>
370386
public static IServiceCollection AddKeyedSingleton(
371387
this IServiceCollection services,
372-
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type serviceType,
388+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
389+
Type serviceType,
373390
object? serviceKey,
374391
Action<DecoratorChain> chainBuilder)
375392
{
@@ -385,7 +402,8 @@ public static IServiceCollection AddKeyedSingleton(
385402
/// <param name="serviceKey">The <see cref="ServiceDescriptor.ServiceKey"/> of the service.</param>
386403
/// <returns>A reference to this instance after the operation has completed.</returns>
387404
/// <seealso cref="ServiceLifetime.Singleton"/>
388-
public static IServiceCollection AddKeyedSingleton<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TService>(
405+
public static IServiceCollection AddKeyedSingleton<
406+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TService>(
389407
this IServiceCollection services,
390408
object? serviceKey,
391409
Action<DecoratorChain> chainBuilder)
@@ -486,7 +504,8 @@ private static IServiceCollection AddKeyed(
486504
IServiceCollection collection,
487505
Type serviceType,
488506
object? serviceKey,
489-
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type implementationType,
507+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
508+
Type implementationType,
490509
ServiceLifetime lifetime,
491510
Action<DecoratorChain> chainBuilder)
492511
{

Eocron.DependencyInjection/ServiceCollectionExtensions.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,6 @@ private static IServiceCollection Add(
451451
return collection;
452452
}
453453

454-
private static DecoratorChain ToChain(Action<DecoratorChain> chainBuilder)
455-
{
456-
var chain = new DecoratorChain();
457-
chainBuilder(chain);
458-
return chain;
459-
}
454+
460455
}
461456
}

0 commit comments

Comments
 (0)