Skip to content

Commit b0e2722

Browse files
committed
Simplifies GitVersionContext creation
Removes GitVersionOptions parameter from IGitVersionContextFactory.Create().
1 parent 29c16f6 commit b0e2722

File tree

6 files changed

+7
-9
lines changed

6 files changed

+7
-9
lines changed

src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,8 @@ private static IServiceProvider GetServiceProvider(GitVersionOptions gitVersionO
695695
services.AddSingleton<IGitVersionContextFactory, GitVersionContextFactory>();
696696
services.AddSingleton(sp =>
697697
{
698-
var options = sp.GetRequiredService<IOptions<GitVersionOptions>>();
699698
var contextFactory = sp.GetRequiredService<IGitVersionContextFactory>();
700-
return new Lazy<GitVersionContext>(() => contextFactory.Create(options.Value));
699+
return new Lazy<GitVersionContext>(() => contextFactory.Create());
701700
});
702701
if (log != null) services.AddSingleton(log);
703702
if (fileSystem != null) services.AddSingleton(fileSystem);

src/GitVersion.Core/Core/Abstractions/IGitVersionContextFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ namespace GitVersion;
22

33
public interface IGitVersionContextFactory
44
{
5-
GitVersionContext Create(GitVersionOptions gitVersionOptions);
5+
GitVersionContext Create();
66
}

src/GitVersion.Core/Core/GitVersionContextFactory.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ internal class GitVersionContextFactory(
1818
private readonly ITaggedSemanticVersionRepository taggedSemanticVersionRepository = taggedSemanticVersionRepository.NotNull();
1919
private readonly IOptions<GitVersionOptions> options = options.NotNull();
2020

21-
public GitVersionContext Create(GitVersionOptions gitVersionOptions)
21+
public GitVersionContext Create()
2222
{
23-
var overrideConfiguration = this.options.Value.ConfigurationInfo.OverrideConfiguration;
23+
var gitVersionOptions = this.options.Value;
24+
var overrideConfiguration = gitVersionOptions.ConfigurationInfo.OverrideConfiguration;
2425
var configuration = this.configurationProvider.Provide(overrideConfiguration);
2526

2627
var currentBranch = this.repositoryStore.GetTargetBranch(gitVersionOptions.RepositoryInfo.TargetBranch)

src/GitVersion.Core/GitVersionCoreModule.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using GitVersion.VersionCalculation;
55
using GitVersion.VersionCalculation.Caching;
66
using Microsoft.Extensions.DependencyInjection;
7-
using Microsoft.Extensions.Options;
87

98
namespace GitVersion;
109

@@ -25,9 +24,8 @@ public void RegisterTypes(IServiceCollection services)
2524
services.AddSingleton<IGitVersionContextFactory, GitVersionContextFactory>();
2625
services.AddSingleton(sp =>
2726
{
28-
var options = sp.GetRequiredService<IOptions<GitVersionOptions>>();
2927
var contextFactory = sp.GetRequiredService<IGitVersionContextFactory>();
30-
return new Lazy<GitVersionContext>(() => contextFactory.Create(options.Value));
28+
return new Lazy<GitVersionContext>(() => contextFactory.Create());
3129
});
3230

3331
services.AddModule(new GitVersionCommonModule());

src/GitVersion.Core/PublicAPI.Shipped.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ GitVersion.IGitPreparer.Prepare() -> void
364364
GitVersion.IGitVersionCalculateTool
365365
GitVersion.IGitVersionCalculateTool.CalculateVersionVariables() -> GitVersion.OutputVariables.GitVersionVariables!
366366
GitVersion.IGitVersionContextFactory
367-
GitVersion.IGitVersionContextFactory.Create(GitVersion.GitVersionOptions! gitVersionOptions) -> GitVersion.GitVersionContext!
368367
GitVersion.IGitVersionModule
369368
GitVersion.IGitVersionModule.FindAllDerivedTypes<T>(System.Reflection.Assembly? assembly) -> System.Collections.Generic.IEnumerable<System.Type!>!
370369
GitVersion.IGitVersionModule.RegisterTypes(Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> void

src/GitVersion.Core/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ GitVersion.Common.IRepositoryStore.GetCommitsReacheableFrom(GitVersion.Git.IComm
33
GitVersion.Git.ICommit.Id.get -> GitVersion.Git.IObjectId!
44
GitVersion.Git.ICommit.Sha.get -> string!
55
GitVersion.Git.IGitRepository.References.get -> GitVersion.Git.IReferenceCollection!
6+
GitVersion.IGitVersionContextFactory.Create() -> GitVersion.GitVersionContext!

0 commit comments

Comments
 (0)