Skip to content

Commit

Permalink
ReSharper cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sorensenmatias committed Mar 3, 2024
1 parent 5a5486d commit 5aaca93
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 74 deletions.
61 changes: 32 additions & 29 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyName>ServiceProviderValidationExtensions.Tests</AssemblyName>
<RootNamespace>ServiceProviderValidationExtensions.Tests</RootNamespace>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
<LangVersion>11.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PropertyGroup>
<AssemblyName>ServiceProviderValidationExtensions.Tests</AssemblyName>
<RootNamespace>ServiceProviderValidationExtensions.Tests</RootNamespace>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
<LangVersion>11.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" Condition="'$(TargetFramework)' == 'net8.0'" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" Condition="'$(TargetFramework)' == 'net8.0'" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0"
Condition="'$(TargetFramework)' == 'net8.0'" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0"
Condition="'$(TargetFramework)' == 'net8.0'" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\src\ServiceProviderValidationExtensions.Hosting\ServiceProviderValidationExtensions.Hosting.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference
Include="..\src\ServiceProviderValidationExtensions.Hosting\ServiceProviderValidationExtensions.Hosting.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ServiceProviderValidationExtensions\ServiceProviderValidationExtensions.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ServiceProviderValidationExtensions\ServiceProviderValidationExtensions.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static ValidationRegistrations CreateAndPersistInstance(IServiceCollecti
return services[0].ImplementationInstance as ValidationRegistrations;
}


private static (ValidationRegistrations validationRegistrations, ServiceDescriptor serviceDescriptor)? SearchForValidationRegistrations(IServiceCollection services)
{
var serviceDescriptor = services.FirstOrDefault(sd => sd.ImplementationInstance is ValidationRegistrations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ public static bool IsDerivedFromGenericParent(this Type? type, Type parentType)
{
throw new ArgumentException("type must be generic", nameof(parentType));
}

if (type == null || type == typeof(object))
{
return false;
}

if (type.IsGenericType && type.GetGenericTypeDefinition() == parentType)
{
return true;
Expand Down
60 changes: 30 additions & 30 deletions src/ServiceProviderValidationExtensions/ReportConfigurer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ namespace ServiceProviderValidationExtensions;

public sealed class ReportConfigurer : IReportConfigurer
{
private Action<DuplicateServiceContent>? _duplicateServiceAction;
private readonly IList<Type> _duplicateServiceExclusions = new List<Type>();

private Action<DuplicateServiceContent>? _duplicateServiceAction;

public void Report(IServiceCollection serviceCollection)
{
ReportDuplicateServices(serviceCollection);
}

public ReportConfigurer OnDuplicateService(Action<DuplicateServiceContent> action,
Action<ReportingDuplicateServiceConfiguration>? configuration = null)
{
Expand All @@ -16,35 +21,8 @@ public ReportConfigurer OnDuplicateService(Action<DuplicateServiceContent> actio
{
configuration(new ReportingDuplicateServiceConfiguration(this));
}

return this;
}

public sealed class ReportingDuplicateServiceConfiguration
{
private readonly ReportConfigurer _reportConfigurer;

internal ReportingDuplicateServiceConfiguration(ReportConfigurer reportConfigurer)
{
_reportConfigurer = reportConfigurer;
}

public ReportingDuplicateServiceConfiguration Except<T>()
{
_reportConfigurer._duplicateServiceExclusions.Add(typeof(T));
return this;
}

public ReportingDuplicateServiceConfiguration Except(Type type)
{
_reportConfigurer._duplicateServiceExclusions.Add(type);
return this;
}
}

public void Report(IServiceCollection serviceCollection)
{
ReportDuplicateServices(serviceCollection);
return this;
}

private void ReportDuplicateServices(IServiceCollection serviceCollection)
Expand Down Expand Up @@ -91,6 +69,28 @@ private void ReportDuplicateServices(IServiceCollection serviceCollection)
}
}

public sealed class ReportingDuplicateServiceConfiguration
{
private readonly ReportConfigurer _reportConfigurer;

internal ReportingDuplicateServiceConfiguration(ReportConfigurer reportConfigurer)
{
_reportConfigurer = reportConfigurer;
}

public ReportingDuplicateServiceConfiguration Except<T>()
{
_reportConfigurer._duplicateServiceExclusions.Add(typeof(T));
return this;
}

public ReportingDuplicateServiceConfiguration Except(Type type)
{
_reportConfigurer._duplicateServiceExclusions.Add(type);
return this;
}
}

public sealed class DuplicateServiceContent
{
public DuplicateServiceContent(TypeInfo serviceType, IReadOnlyCollection<TypeInfo> implementationTypes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static void Validate(this IServiceProvider serviceProvider)
}

/// <summary>
/// Marks the <see cref="TService"/> as exclusive (only one registration can exist in the ServiceProvider).
/// Marks the <see cref="TService" /> as exclusive (only one registration can exist in the ServiceProvider).

Check warning on line 174 in src/ServiceProviderValidationExtensions/ServiceCollectionValidationExtensions.cs

View workflow job for this annotation

GitHub Actions / create_nuget

XML comment has cref attribute 'TService' that could not be resolved

Check warning on line 174 in src/ServiceProviderValidationExtensions/ServiceCollectionValidationExtensions.cs

View workflow job for this annotation

GitHub Actions / create_nuget

XML comment has cref attribute 'TService' that could not be resolved

Check warning on line 174 in src/ServiceProviderValidationExtensions/ServiceCollectionValidationExtensions.cs

View workflow job for this annotation

GitHub Actions / run_test

XML comment has cref attribute 'TService' that could not be resolved

Check warning on line 174 in src/ServiceProviderValidationExtensions/ServiceCollectionValidationExtensions.cs

View workflow job for this annotation

GitHub Actions / run_test

XML comment has cref attribute 'TService' that could not be resolved
/// </summary>
public static IServiceCollection SetExclusiveService<TService>(this IServiceCollection services)
where TService : class
Expand All @@ -197,7 +197,8 @@ private static void RegisterExclusiveService<TService>(this IServiceCollection s
}

/// <summary>
/// Marks the (<see cref="TService"/>,<see cref="TImplementation"/>) combination as exclusive (only one registration can exist in the ServiceProvider).
/// Marks the (<see cref="TService" />,<see cref="TImplementation" />) combination as exclusive (only one registration

Check warning on line 200 in src/ServiceProviderValidationExtensions/ServiceCollectionValidationExtensions.cs

View workflow job for this annotation

GitHub Actions / create_nuget

XML comment has cref attribute 'TService' that could not be resolved

Check warning on line 200 in src/ServiceProviderValidationExtensions/ServiceCollectionValidationExtensions.cs

View workflow job for this annotation

GitHub Actions / create_nuget

XML comment has cref attribute 'TImplementation' that could not be resolved

Check warning on line 200 in src/ServiceProviderValidationExtensions/ServiceCollectionValidationExtensions.cs

View workflow job for this annotation

GitHub Actions / create_nuget

XML comment has cref attribute 'TService' that could not be resolved

Check warning on line 200 in src/ServiceProviderValidationExtensions/ServiceCollectionValidationExtensions.cs

View workflow job for this annotation

GitHub Actions / create_nuget

XML comment has cref attribute 'TImplementation' that could not be resolved

Check warning on line 200 in src/ServiceProviderValidationExtensions/ServiceCollectionValidationExtensions.cs

View workflow job for this annotation

GitHub Actions / run_test

XML comment has cref attribute 'TService' that could not be resolved

Check warning on line 200 in src/ServiceProviderValidationExtensions/ServiceCollectionValidationExtensions.cs

View workflow job for this annotation

GitHub Actions / run_test

XML comment has cref attribute 'TImplementation' that could not be resolved

Check warning on line 200 in src/ServiceProviderValidationExtensions/ServiceCollectionValidationExtensions.cs

View workflow job for this annotation

GitHub Actions / run_test

XML comment has cref attribute 'TService' that could not be resolved

Check warning on line 200 in src/ServiceProviderValidationExtensions/ServiceCollectionValidationExtensions.cs

View workflow job for this annotation

GitHub Actions / run_test

XML comment has cref attribute 'TImplementation' that could not be resolved
/// can exist in the ServiceProvider).
/// </summary>
public static void SetExclusiveImplementation<TService, TImplementation>(this IServiceCollection services)
where TImplementation : class
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">


<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
</ItemGroup>


<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
</ItemGroup>

</Project>

0 comments on commit 5aaca93

Please sign in to comment.