Skip to content

Commit 10db929

Browse files
committed
Make connection factory static
1 parent 3e12c35 commit 10db929

62 files changed

Lines changed: 130 additions & 324 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/SeqCli/Cli/Commands/ApiKey/CreateCommand.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ namespace SeqCli.Cli.Commands.ApiKey;
3232
Example = "seqcli apikey create -t 'Test API Key' -p Environment=Test")]
3333
class CreateCommand : Command
3434
{
35-
readonly SeqConnectionFactory _connectionFactory;
36-
3735
readonly ConnectionFeature _connection;
3836
readonly PropertiesFeature _properties;
3937
readonly OutputFormatFeature _output;
@@ -43,10 +41,8 @@ class CreateCommand : Command
4341
string[]? _permissions;
4442
bool _useServerTimestamps, _connectPasswordStdin;
4543

46-
public CreateCommand(SeqConnectionFactory connectionFactory)
44+
public CreateCommand()
4745
{
48-
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
49-
5046
Options.Add(
5147
"t=|title=",
5248
"A title for the API key",
@@ -189,13 +185,13 @@ protected override async Task<int> Run()
189185
_connectPassword = await Console.In.ReadLineAsync();
190186
}
191187

192-
var (url, _) = _connectionFactory.GetConnectionDetails(_connection, config);
188+
var (url, _) = SeqConnectionFactory.GetConnectionDetails(_connection, config);
193189
connection = new SeqConnection(url);
194190
await connection.Users.LoginAsync(_connectUsername, _connectPassword ?? "");
195191
}
196192
else
197193
{
198-
connection = _connectionFactory.Connect(_connection, config);
194+
connection = SeqConnectionFactory.Connect(_connection, config);
199195
}
200196

201197
return connection;

src/SeqCli/Cli/Commands/ApiKey/ListCommand.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,13 @@ namespace SeqCli.Cli.Commands.ApiKey;
2424
[Command("apikey", "list", "List available API keys", Example="seqcli apikey list")]
2525
class ListCommand : Command
2626
{
27-
readonly SeqConnectionFactory _connectionFactory;
28-
2927
readonly EntityIdentityFeature _entityIdentity;
3028
readonly ConnectionFeature _connection;
3129
readonly OutputFormatFeature _output;
3230
readonly StoragePathFeature _storagePath;
3331

34-
public ListCommand(SeqConnectionFactory connectionFactory)
32+
public ListCommand()
3533
{
36-
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
37-
3834
_entityIdentity = Enable(new EntityIdentityFeature("API key", "list"));
3935
_output = Enable<OutputFormatFeature>();
4036
_storagePath = Enable<StoragePathFeature>();
@@ -44,7 +40,7 @@ public ListCommand(SeqConnectionFactory connectionFactory)
4440
protected override async Task<int> Run()
4541
{
4642
var config = RuntimeConfigurationLoader.Load(_storagePath);
47-
var connection = _connectionFactory.Connect(_connection, config);
43+
var connection = SeqConnectionFactory.Connect(_connection, config);
4844

4945
var list = _entityIdentity.Id != null ?
5046
new[] { await connection.ApiKeys.FindAsync(_entityIdentity.Id) } :

src/SeqCli/Cli/Commands/ApiKey/RemoveCommand.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,12 @@ namespace SeqCli.Cli.Commands.ApiKey;
2626
Example="seqcli apikey remove -t 'Test API Key'")]
2727
class RemoveCommand : Command
2828
{
29-
readonly SeqConnectionFactory _connectionFactory;
30-
3129
readonly EntityIdentityFeature _entityIdentity;
3230
readonly ConnectionFeature _connection;
3331
readonly StoragePathFeature _storagePath;
3432

35-
public RemoveCommand(SeqConnectionFactory connectionFactory)
33+
public RemoveCommand()
3634
{
37-
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
38-
3935
_entityIdentity = Enable(new EntityIdentityFeature("API key", "remove"));
4036
_connection = Enable<ConnectionFeature>();
4137
_storagePath = Enable<StoragePathFeature>();
@@ -50,7 +46,7 @@ protected override async Task<int> Run()
5046
}
5147

5248
var config = RuntimeConfigurationLoader.Load(_storagePath);
53-
var connection = _connectionFactory.Connect(_connection, config);
49+
var connection = SeqConnectionFactory.Connect(_connection, config);
5450

5551
var toRemove = _entityIdentity.Id != null ? [await connection.ApiKeys.FindAsync(_entityIdentity.Id)]
5652
:

src/SeqCli/Cli/Commands/ApiKey/UpdateCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ namespace SeqCli.Cli.Commands.ApiKey;
2020
[Command("apikey", "update",
2121
"Update an existing API key",
2222
Example="seqcli apikey update --json '{...}'")]
23-
class UpdateCommand(SeqConnectionFactory connectionFactory):
24-
Shared.UpdateCommand(connectionFactory, "apikey", nameof(SeqConnection.ApiKeys), "API key");
23+
class UpdateCommand():
24+
Shared.UpdateCommand("apikey", nameof(SeqConnection.ApiKeys), "API key");
2525

src/SeqCli/Cli/Commands/App/InstallCommand.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,14 @@ namespace SeqCli.Cli.Commands.App;
2929
// ReSharper disable once UnusedType.Global
3030
class InstallCommand : Command
3131
{
32-
readonly SeqConnectionFactory _connectionFactory;
33-
3432
readonly ConnectionFeature _connection;
3533
readonly OutputFormatFeature _output;
3634
readonly StoragePathFeature _storagePath;
3735

3836
string? _packageId, _version, _feedId;
3937

40-
public InstallCommand(SeqConnectionFactory connectionFactory)
38+
public InstallCommand()
4139
{
42-
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
43-
4440
Options.Add(
4541
"package-id=",
4642
"The package id of the app to install",
@@ -70,7 +66,7 @@ protected override async Task<int> Run()
7066
}
7167

7268
var config = RuntimeConfigurationLoader.Load(_storagePath);
73-
var connection = _connectionFactory.Connect(_connection, config);
69+
var connection = SeqConnectionFactory.Connect(_connection, config);
7470

7571
var feedId = _feedId;
7672
if (feedId == null)

src/SeqCli/Cli/Commands/App/ListCommand.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ namespace SeqCli.Cli.Commands.App;
1010
[Command("app", "list", "List installed app packages", Example="seqcli app list")]
1111
class ListCommand : Command
1212
{
13-
readonly SeqConnectionFactory _connectionFactory;
14-
1513
string? _title, _id;
1614
readonly ConnectionFeature _connection;
1715
readonly OutputFormatFeature _output;
@@ -20,10 +18,8 @@ class ListCommand : Command
2018
string? PackageId => string.IsNullOrWhiteSpace(_title) ? null : _title.Trim();
2119
string? Id => string.IsNullOrWhiteSpace(_id) ? null : _id.Trim();
2220

23-
public ListCommand(SeqConnectionFactory connectionFactory)
21+
public ListCommand()
2422
{
25-
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
26-
2723
Options.Add(
2824
"package-id=",
2925
"The package id of the app(s) to list",
@@ -48,7 +44,7 @@ protected override async Task<int> Run()
4844
}
4945

5046
var config = RuntimeConfigurationLoader.Load(_storagePath);
51-
var connection = _connectionFactory.Connect(_connection, config);
47+
var connection = SeqConnectionFactory.Connect(_connection, config);
5248

5349
var list = Id != null ? [await connection.Apps.FindAsync(Id)]
5450
:

src/SeqCli/Cli/Commands/App/UninstallCommand.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,12 @@ namespace SeqCli.Cli.Commands.App;
1414
// ReSharper disable once UnusedType.Global
1515
class UninstallCommand : Command
1616
{
17-
readonly SeqConnectionFactory _connectionFactory;
18-
1917
string? _packageId, _id;
2018
readonly ConnectionFeature _connection;
2119
readonly StoragePathFeature _storagePath;
2220

23-
public UninstallCommand(SeqConnectionFactory connectionFactory)
21+
public UninstallCommand()
2422
{
25-
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
26-
2723
Options.Add(
2824
"package-id=",
2925
"The package id of the app package to uninstall",
@@ -47,7 +43,7 @@ protected override async Task<int> Run()
4743
}
4844

4945
var config = RuntimeConfigurationLoader.Load(_storagePath);
50-
var connection = _connectionFactory.Connect(_connection, config);
46+
var connection = SeqConnectionFactory.Connect(_connection, config);
5147

5248
var toRemove = _id != null ? [await connection.Apps.FindAsync(_id)]
5349
: (await connection.Apps.ListAsync())

src/SeqCli/Cli/Commands/App/UpdateCommand.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,15 @@ namespace SeqCli.Cli.Commands.App;
2828
// ReSharper disable once UnusedType.Global
2929
class UpdateCommand : Command
3030
{
31-
readonly SeqConnectionFactory _connectionFactory;
32-
3331
readonly ConnectionFeature _connection;
3432
readonly OutputFormatFeature _output;
3533
readonly StoragePathFeature _storagePath;
3634

3735
string? _id, _name, _version;
3836
bool _all, _force;
3937

40-
public UpdateCommand(SeqConnectionFactory connectionFactory)
38+
public UpdateCommand()
4139
{
42-
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
43-
4440
Options.Add(
4541
"i=|id=",
4642
"The id of a single installed app to update",
@@ -94,7 +90,7 @@ protected override async Task<int> Run()
9490
}
9591

9692
var config = RuntimeConfigurationLoader.Load(_storagePath);
97-
var connection = _connectionFactory.Connect(_connection, config);
93+
var connection = SeqConnectionFactory.Connect(_connection, config);
9894
var output = _output.GetOutputFormat(config);
9995

10096
var apps = await connection.Apps.ListAsync();

src/SeqCli/Cli/Commands/AppInstance/CreateCommand.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ namespace SeqCli.Cli.Commands.AppInstance;
1616
Example = "seqcli appinstance create -t 'Email Ops' --app hostedapp-314159 -p To=ops@example.com")]
1717
class CreateCommand : Command
1818
{
19-
readonly SeqConnectionFactory _connectionFactory;
20-
2119
readonly ConnectionFeature _connection;
2220
readonly OutputFormatFeature _output;
2321
readonly StoragePathFeature _storagePath;
@@ -27,10 +25,8 @@ class CreateCommand : Command
2725
readonly List<string> _overridable = new();
2826
bool _streamIncomingEvents;
2927

30-
public CreateCommand(SeqConnectionFactory connectionFactory)
28+
public CreateCommand()
3129
{
32-
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
33-
3430
Options.Add(
3531
"t=|title=",
3632
"A title for the app instance",
@@ -78,7 +74,7 @@ public CreateCommand(SeqConnectionFactory connectionFactory)
7874
protected override async Task<int> Run()
7975
{
8076
var config = RuntimeConfigurationLoader.Load(_storagePath);
81-
var connection = _connectionFactory.Connect(_connection, config);
77+
var connection = SeqConnectionFactory.Connect(_connection, config);
8278

8379
AppInstanceEntity instance = await connection.AppInstances.TemplateAsync(_appId)!;
8480

src/SeqCli/Cli/Commands/AppInstance/ListCommand.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,13 @@ namespace SeqCli.Cli.Commands.AppInstance;
1010
[Command("appinstance", "list", "List instances of installed apps", Example="seqcli appinstance list")]
1111
class ListCommand : Command
1212
{
13-
readonly SeqConnectionFactory _connectionFactory;
14-
1513
readonly EntityIdentityFeature _entityIdentity;
1614
readonly ConnectionFeature _connection;
1715
readonly OutputFormatFeature _output;
1816
readonly StoragePathFeature _storagePath;
1917

20-
public ListCommand(SeqConnectionFactory connectionFactory)
18+
public ListCommand()
2119
{
22-
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
23-
2420
_entityIdentity = Enable(new EntityIdentityFeature("app instance", "list"));
2521
_output = Enable<OutputFormatFeature>();
2622
_storagePath = Enable<StoragePathFeature>();
@@ -30,7 +26,7 @@ public ListCommand(SeqConnectionFactory connectionFactory)
3026
protected override async Task<int> Run()
3127
{
3228
var config = RuntimeConfigurationLoader.Load(_storagePath);
33-
var connection = _connectionFactory.Connect(_connection, config);
29+
var connection = SeqConnectionFactory.Connect(_connection, config);
3430

3531
var list = _entityIdentity.Id != null ? [await connection.AppInstances.FindAsync(_entityIdentity.Id)]
3632
:

0 commit comments

Comments
 (0)