Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use option pattern to configure azure table name #721

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/BaGet.Azure/Configuration/AzureTableOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ public class AzureTableOptions
{
[Required]
public string ConnectionString { get; set; }

[Required] public string TableName { get; set; } = "Packages";
}
}
9 changes: 6 additions & 3 deletions src/BaGet.Azure/Table/TablePackageDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using BaGet.Core;
using Microsoft.Azure.Cosmos.Table;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NuGet.Versioning;

namespace BaGet.Azure
Expand All @@ -15,20 +16,22 @@ namespace BaGet.Azure
/// </summary>
public class TablePackageDatabase : IPackageDatabase
{
private const string TableName = "Packages";
private const int MaxPreconditionFailures = 5;

private readonly string _tableName;
private readonly TableOperationBuilder _operationBuilder;
private readonly CloudTable _table;
private readonly ILogger<TablePackageDatabase> _logger;

public TablePackageDatabase(
TableOperationBuilder operationBuilder,
CloudTableClient client,
ILogger<TablePackageDatabase> logger)
ILogger<TablePackageDatabase> logger,
IOptions<AzureTableOptions> options)
{
_operationBuilder = operationBuilder ?? throw new ArgumentNullException(nameof(operationBuilder));
_table = client?.GetTableReference(TableName) ?? throw new ArgumentNullException(nameof(client));
_tableName = options.Value.TableName;
_table = client?.GetTableReference(_tableName) ?? throw new ArgumentNullException(nameof(client));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}

Expand Down
10 changes: 6 additions & 4 deletions src/BaGet.Azure/Table/TableSearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@
using BaGet.Core;
using BaGet.Protocol.Models;
using Microsoft.Azure.Cosmos.Table;
using Microsoft.Extensions.Options;

namespace BaGet.Azure
{
public class TableSearchService : ISearchService
{
private const string TableName = "Packages";

private readonly string _tableName;
private readonly CloudTable _table;
private readonly ISearchResponseBuilder _responseBuilder;

public TableSearchService(
CloudTableClient client,
ISearchResponseBuilder responseBuilder)
ISearchResponseBuilder responseBuilder,
IOptions<AzureTableOptions> options)
{
_table = client?.GetTableReference(TableName) ?? throw new ArgumentNullException(nameof(client));
_tableName = options.Value.TableName;
_table = client?.GetTableReference(_tableName) ?? throw new ArgumentNullException(nameof(client));
_responseBuilder = responseBuilder ?? throw new ArgumentNullException(nameof(responseBuilder));
}

Expand Down