Skip to content

Commit

Permalink
Merge pull request #62 from pfpack/feature/minor-refactor-resolver
Browse files Browse the repository at this point in the history
feature/minor-refactor-resolver
  • Loading branch information
andreise authored Dec 14, 2023
2 parents a8c239a + 5fb75ab commit 72bbd96
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 29 deletions.
8 changes: 4 additions & 4 deletions src/dependency-core/Core.Tests/Dependency.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.69" />
<PackageReference Include="PrimeFuncPack.UnitTest.Data" Version="3.0.0" />
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="PrimeFuncPack.UnitTest.Data" Version="3.1.0" />
<PackageReference Include="xunit" Version="2.6.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ partial class InternalDependencyResolver<TDependency>
public InternalDependencyResolver(
TDependency instance)
=>
(this.instance, tag) = (instance, InternalDependencyResolverTag.Instance);
(this.instance, tag) = (instance, Tag.Instance);

public InternalDependencyResolver(
Func<TDependency> factory)
=>
(this.factory, tag) = (factory, InternalDependencyResolverTag.Factory);
(this.factory, tag) = (factory, Tag.Factory);

public InternalDependencyResolver(
Func<IServiceProvider, TDependency> resolver)
=>
(this.resolver, tag) = (resolver, InternalDependencyResolverTag.Resolver);
(this.resolver, tag) = (resolver, Tag.Resolver);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@ partial class InternalDependencyResolver<TDependency>
{
public TDependency Invoke(IServiceProvider serviceProvider) => tag switch
{
InternalDependencyResolverTag.Instance
=>
instance!,
Tag.Instance => instance!,

InternalDependencyResolverTag.Factory
=>
factory!.Invoke(),
Tag.Factory => factory!.Invoke(),

InternalDependencyResolverTag.Resolver
=>
resolver!.Invoke(serviceProvider),
Tag.Resolver => resolver!.Invoke(serviceProvider),

_ => throw new InvalidOperationException("An unexpected tag value.")
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace PrimeFuncPack;

partial class InternalDependencyResolver<TDependency>
{
private enum Tag
{
Instance,
Factory,
Resolver
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace PrimeFuncPack;

internal sealed partial class InternalDependencyResolver<TDependency>
{
private readonly InternalDependencyResolverTag tag;
private readonly Tag tag;

private readonly TDependency? instance;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.69" />
<PackageReference Include="PrimeFuncPack.UnitTest.Data" Version="3.0.0" />
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="PrimeFuncPack.UnitTest.Data" Version="3.1.0" />
<PackageReference Include="xunit" Version="2.6.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down

0 comments on commit 72bbd96

Please sign in to comment.