Skip to content

Commit 9113b43

Browse files
committed
use primary constructors - GitVersion.App
1 parent db1f675 commit 9113b43

File tree

5 files changed

+38
-65
lines changed

5 files changed

+38
-65
lines changed

src/GitVersion.App/ArgumentParser.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,17 @@
66

77
namespace GitVersion;
88

9-
internal class ArgumentParser : IArgumentParser
9+
internal class ArgumentParser(IEnvironment environment, ICurrentBuildAgent buildAgent, IConsole console, IGlobbingResolver globbingResolver)
10+
: IArgumentParser
1011
{
11-
private readonly IEnvironment environment;
12-
private readonly ICurrentBuildAgent buildAgent;
13-
private readonly IConsole console;
14-
private readonly IGlobbingResolver globbingResolver;
12+
private readonly IEnvironment environment = environment.NotNull();
13+
private readonly ICurrentBuildAgent buildAgent = buildAgent.NotNull();
14+
private readonly IConsole console = console.NotNull();
15+
private readonly IGlobbingResolver globbingResolver = globbingResolver.NotNull();
16+
1517
private const string defaultOutputFileName = "GitVersion.json";
1618
private static readonly IEnumerable<string> availableVariables = GitVersionVariables.AvailableVariables;
1719

18-
public ArgumentParser(IEnvironment environment, ICurrentBuildAgent buildAgent, IConsole console, IGlobbingResolver globbingResolver)
19-
{
20-
this.environment = environment.NotNull();
21-
this.console = console.NotNull();
22-
this.globbingResolver = globbingResolver.NotNull();
23-
this.buildAgent = buildAgent.NotNull();
24-
}
25-
2620
public Arguments ParseArguments(string commandLineArguments)
2721
{
2822
var arguments = QuotedStringHelpers.SplitUnquoted(commandLineArguments, ' ');

src/GitVersion.App/GitVersionApp.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,14 @@
55

66
namespace GitVersion;
77

8-
internal class GitVersionApp : IHostedService
8+
internal class GitVersionApp(ILog log, IHostApplicationLifetime applicationLifetime, IGitVersionExecutor gitVersionExecutor, IOptions<GitVersionOptions> options)
9+
: IHostedService
910
{
10-
private readonly IHostApplicationLifetime applicationLifetime;
11-
private readonly IGitVersionExecutor gitVersionExecutor;
12-
private readonly ILog log;
13-
private readonly IOptions<GitVersionOptions> options;
11+
private readonly ILog log = log.NotNull();
12+
private readonly IHostApplicationLifetime applicationLifetime = applicationLifetime.NotNull();
13+
private readonly IGitVersionExecutor gitVersionExecutor = gitVersionExecutor.NotNull();
14+
private readonly IOptions<GitVersionOptions> options = options.NotNull();
1415

15-
public GitVersionApp(IHostApplicationLifetime applicationLifetime, IGitVersionExecutor gitVersionExecutor, ILog log, IOptions<GitVersionOptions> options)
16-
{
17-
this.options = options.NotNull();
18-
this.applicationLifetime = applicationLifetime.NotNull();
19-
this.gitVersionExecutor = gitVersionExecutor.NotNull();
20-
this.log = log.NotNull();
21-
}
2216
public Task StartAsync(CancellationToken cancellationToken)
2317
{
2418
try

src/GitVersion.App/GitVersionExecutor.cs

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,27 @@
55

66
namespace GitVersion;
77

8-
internal class GitVersionExecutor : IGitVersionExecutor
8+
internal class GitVersionExecutor(
9+
ILog log,
10+
IConsole console,
11+
IConfigurationFileLocator configurationFileLocator,
12+
IConfigurationProvider configurationProvider,
13+
IGitVersionCalculateTool gitVersionCalculateTool,
14+
IGitVersionOutputTool gitVersionOutputTool,
15+
IVersionWriter versionWriter,
16+
IHelpWriter helpWriter,
17+
IGitRepositoryInfo repositoryInfo)
18+
: IGitVersionExecutor
919
{
10-
private readonly ILog log;
11-
private readonly IConsole console;
12-
private readonly IConfigurationFileLocator configurationFileLocator;
13-
private readonly IConfigurationProvider configurationProvider;
14-
private readonly IGitVersionCalculateTool gitVersionCalculateTool;
15-
private readonly IGitVersionOutputTool gitVersionOutputTool;
16-
private readonly IVersionWriter versionWriter;
17-
private readonly IHelpWriter helpWriter;
18-
private readonly IGitRepositoryInfo repositoryInfo;
19-
20-
public GitVersionExecutor(ILog log, IConsole console,
21-
IConfigurationFileLocator configurationFileLocator, IConfigurationProvider configurationProvider,
22-
IGitVersionCalculateTool gitVersionCalculateTool, IGitVersionOutputTool gitVersionOutputTool,
23-
IVersionWriter versionWriter, IHelpWriter helpWriter, IGitRepositoryInfo repositoryInfo)
24-
{
25-
this.log = log.NotNull();
26-
this.console = console.NotNull();
27-
this.configurationFileLocator = configurationFileLocator.NotNull();
28-
this.configurationProvider = configurationProvider.NotNull();
29-
30-
this.gitVersionCalculateTool = gitVersionCalculateTool.NotNull();
31-
this.gitVersionOutputTool = gitVersionOutputTool.NotNull();
32-
33-
this.versionWriter = versionWriter.NotNull();
34-
this.helpWriter = helpWriter.NotNull();
35-
this.repositoryInfo = repositoryInfo.NotNull();
36-
}
20+
private readonly ILog log = log.NotNull();
21+
private readonly IConsole console = console.NotNull();
22+
private readonly IConfigurationFileLocator configurationFileLocator = configurationFileLocator.NotNull();
23+
private readonly IConfigurationProvider configurationProvider = configurationProvider.NotNull();
24+
private readonly IGitVersionCalculateTool gitVersionCalculateTool = gitVersionCalculateTool.NotNull();
25+
private readonly IGitVersionOutputTool gitVersionOutputTool = gitVersionOutputTool.NotNull();
26+
private readonly IVersionWriter versionWriter = versionWriter.NotNull();
27+
private readonly IHelpWriter helpWriter = helpWriter.NotNull();
28+
private readonly IGitRepositoryInfo repositoryInfo = repositoryInfo.NotNull();
3729

3830
public int Execute(GitVersionOptions gitVersionOptions)
3931
{

src/GitVersion.App/HelpWriter.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,10 @@
44

55
namespace GitVersion;
66

7-
internal class HelpWriter : IHelpWriter
7+
internal class HelpWriter(IVersionWriter versionWriter, IConsole console) : IHelpWriter
88
{
9-
private readonly IVersionWriter versionWriter;
10-
private readonly IConsole console;
11-
12-
public HelpWriter(IVersionWriter versionWriter, IConsole console)
13-
{
14-
this.versionWriter = versionWriter.NotNull();
15-
this.console = console.NotNull();
16-
}
9+
private readonly IVersionWriter versionWriter = versionWriter.NotNull();
10+
private readonly IConsole console = console.NotNull();
1711

1812
public void Write() => WriteTo(this.console.WriteLine);
1913

src/GitVersion.App/VersionWriter.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33

44
namespace GitVersion;
55

6-
internal class VersionWriter : IVersionWriter
6+
internal class VersionWriter(IConsole console) : IVersionWriter
77
{
8-
private readonly IConsole console;
8+
private readonly IConsole console = console.NotNull();
99

10-
public VersionWriter(IConsole console) => this.console = console.NotNull();
1110
public void Write(Assembly assembly) => WriteTo(assembly, this.console.WriteLine);
1211

1312
public void WriteTo(Assembly assembly, Action<string?> writeAction)

0 commit comments

Comments
 (0)