Skip to content

Commit

Permalink
Automatically generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
portal-quickstart-synchronizer[bot] committed Nov 11, 2024
1 parent 9834f75 commit eef281b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 15 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; }
}
18 changes: 13 additions & 5 deletions services/DemoService.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
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}");

{
Product entity = new()
{
RowKey = "68719518391",
RowKey = "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb",
PartitionKey = "gear-surf-surfboards",
Name = "Yamba Surfboard",
Quantity = 10,
Expand All @@ -40,7 +48,7 @@ public async Task RunAsync(Func<string, Task> writeOutputAync)
{
Product entity = new()
{
RowKey = "68719518371",
RowKey = "bbbbbbbb-1111-2222-3333-cccccccccccc",
PartitionKey = "gear-surf-surfboards",
Name = "Kiama Classic Surfboard",
Quantity = 25,
Expand All @@ -59,7 +67,7 @@ public async Task RunAsync(Func<string, Task> writeOutputAync)

{
Response<Product> response = await client.GetEntityAsync<Product>(
rowKey: "68719518391",
rowKey: "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb",
partitionKey: "gear-surf-surfboards"
);

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 eef281b

Please sign in to comment.