Skip to content

Commit

Permalink
Inline check for already decorated type
Browse files Browse the repository at this point in the history
  • Loading branch information
khellang committed May 23, 2022
1 parent e03e051 commit 5067e34
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Scrutor/Decoration/Decorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ private int DecorateServices(IServiceCollection services)
{
var serviceDescriptor = services[i];

if (IsNotAlreadyDecorated(serviceDescriptor)
&& DecoratorStrategy.CanDecorate(serviceDescriptor.ServiceType))
if (serviceDescriptor.ServiceType is DecoratedType)
{
continue; // Service has already been decorated.
}

if (DecoratorStrategy.CanDecorate(serviceDescriptor.ServiceType))
{
var decoratedType = new DecoratedType(serviceDescriptor.ServiceType);

Expand All @@ -70,7 +74,5 @@ private int DecorateServices(IServiceCollection services)

return decorated;
}

private static bool IsNotAlreadyDecorated(ServiceDescriptor serviceDescriptor) => serviceDescriptor.ServiceType is not DecoratedType;
}
}

0 comments on commit 5067e34

Please sign in to comment.