Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/Scrutor/ServiceCollectionExtensions.Decoration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public static bool TryDecorate(this IServiceCollection services, DecorationStrat
{
var serviceDescriptor = services[i];

if (IsDecorated(serviceDescriptor) || !strategy.CanDecorate(serviceDescriptor))
if (serviceDescriptor.IsDecorated() || !strategy.CanDecorate(serviceDescriptor))
{
continue;
}
Expand All @@ -275,6 +275,14 @@ public static bool TryDecorate(this IServiceCollection services, DecorationStrat
return decorated;
}

/// <summary>
/// Returns <c>true</c> if the specified service is decorated.
/// </summary>
/// <param name="descriptor">The service descriptor.</param>
public static bool IsDecorated(this ServiceDescriptor descriptor) =>
descriptor.ServiceKey is string stringKey
&& stringKey.EndsWith(DecoratedServiceKeySuffix, StringComparison.Ordinal);

private static string? GetDecoratorKey(ServiceDescriptor descriptor)
{
var uniqueId = Guid.NewGuid().ToString("n");
Expand All @@ -291,8 +299,4 @@ public static bool TryDecorate(this IServiceCollection services, DecorationStrat

return null;
}

private static bool IsDecorated(ServiceDescriptor descriptor) =>
descriptor.ServiceKey is string stringKey
&& stringKey.EndsWith(DecoratedServiceKeySuffix, StringComparison.Ordinal);
}