Skip to content

Commit

Permalink
Merge pull request #12 from AzureCosmosDB/auto-20241106145442
Browse files Browse the repository at this point in the history
[AUTO] 2024-11-06 | Merge latest from source repo
  • Loading branch information
2 parents 4f742cf + 05781bd commit e39eb78
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Data.Tables" Version="12.*" />
<PackageReference Include="System.Text.Json" Version="8.*" />
<PackageReference Include="Azure.Data.Tables" Version="12.9.1" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>
</Project>
13 changes: 13 additions & 0 deletions models/Settings/Configuration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Microsoft.Samples.Cosmos.Table.Quickstart.Models.Settings;

public record Configuration
{
public required AzureCosmosDB AzureCosmosDB { get; init; }
}

public record AzureCosmosDB
{
public required string Endpoint { get; init; }

public required string TableName { get; init; }
}
12 changes: 10 additions & 2 deletions services/DemoService.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
using Azure;
using Azure.Data.Tables;
using Microsoft.Extensions.Options;
using Microsoft.Samples.Cosmos.Table.Quickstart.Models;
using Microsoft.Samples.Cosmos.Table.Quickstart.Services.Interfaces;

using Settings = Microsoft.Samples.Cosmos.Table.Quickstart.Models.Settings;

namespace Microsoft.Samples.Cosmos.Table.Quickstart.Services;

public sealed class DemoService(TableServiceClient serviceClient) : IDemoService
public sealed class DemoService(
TableServiceClient serviceClient,
IOptions<Settings.Configuration> configurationOptions
) : IDemoService
{
private readonly Settings.Configuration configuration = configurationOptions.Value;

public string GetEndpoint() => $"{serviceClient.Uri.AbsoluteUri}";

public async Task RunAsync(Func<string, Task> writeOutputAync)
{
TableClient client = serviceClient.GetTableClient(
tableName: "cosmicworks-products"
tableName: configuration.AzureCosmosDB.TableName
);

await writeOutputAync($"Get table:\t{client.Name}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Data.Tables" Version="12.*" />
<PackageReference Include="System.Text.Json" Version="8.*" />
<PackageReference Include="Azure.Data.Tables" Version="12.9.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.0-rc.2.24473.5" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\models\Microsoft.Samples.Cosmos.Table.Quickstart.Models.csproj" />
Expand Down
6 changes: 3 additions & 3 deletions web/Microsoft.Samples.Cosmos.Table.Quickstart.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<UserSecretsId>938c2273-843e-4d6e-98ce-7c6e979eba12</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Data.Tables" Version="12.*" />
<PackageReference Include="Azure.Identity" Version="1.12.1" />
<PackageReference Include="System.Text.Json" Version="8.*" />
<PackageReference Include="Azure.Data.Tables" Version="12.9.1" />
<PackageReference Include="Azure.Identity" Version="1.13.1" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\models\Microsoft.Samples.Cosmos.Table.Quickstart.Models.csproj" />
Expand Down
10 changes: 9 additions & 1 deletion web/Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
using Azure.Data.Tables;
using Azure.Identity;
using Microsoft.Extensions.Options;
using Microsoft.Samples.Cosmos.Table.Quickstart.Services;
using Microsoft.Samples.Cosmos.Table.Quickstart.Services.Interfaces;
using Microsoft.Samples.Cosmos.Table.Quickstart.Web.Components;

using Settings = Microsoft.Samples.Cosmos.Table.Quickstart.Models.Settings;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorComponents().AddInteractiveServerComponents();

builder.Services.AddSingleton<TableServiceClient>((_) =>
builder.Services.AddOptions<Settings.Configuration>().Bind(builder.Configuration.GetSection(nameof(Settings.Configuration)));

builder.Services.AddSingleton<TableServiceClient>((serviceProvider) =>
{
IOptions<Settings.Configuration> configurationOptions = serviceProvider.GetRequiredService<IOptions<Settings.Configuration>>();
Settings.Configuration configuration = configurationOptions.Value;
TableServiceClient serviceClient = new(
connectionString: "<azure-cosmos-db-table-connection-string>"
);
Expand Down
9 changes: 7 additions & 2 deletions web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
"AllowedHosts": "*",
"Configuration": {
"AzureCosmosDB": {
"TableName": "cosmicworks-products"
}
}
}

0 comments on commit e39eb78

Please sign in to comment.