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

Upgrade 'Shopping Cart' sample #8132

Merged
merged 2 commits into from
Nov 18, 2022
Merged
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
4 changes: 2 additions & 2 deletions samples/ShoppingCart/Abstractions/CartItem.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT License.

namespace Orleans.ShoppingCart.Abstractions;

[Serializable, Immutable]
[GenerateSerializer, Immutable]
public sealed record class CartItem(
string UserId,
int Quantity,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="3.6.0" />
<PackageReference Include="Microsoft.Orleans.CodeGenerator.MSBuild" Version="3.6.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Orleans.Sdk" Version="7.0.0" />
</ItemGroup>

</Project>
20 changes: 10 additions & 10 deletions samples/ShoppingCart/Abstractions/ProductDetails.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT License.

namespace Orleans.ShoppingCart.Abstractions;

[Serializable, Immutable]
[GenerateSerializer, Immutable]
public sealed record class ProductDetails
{
public string Id { get; set; } = null!;
public string Name { get; set; } = null!;
public string Description { get; set; } = null!;
public ProductCategory Category { get; set; }
public int Quantity { get; set; }
public decimal UnitPrice { get; set; }
public string DetailsUrl { get; set; } = null!;
public string ImageUrl { get; set; } = null!;
[Id(0)] public string Id { get; set; } = null!;
[Id(1)] public string Name { get; set; } = null!;
[Id(2)] public string Description { get; set; } = null!;
[Id(3)] public ProductCategory Category { get; set; }
[Id(4)] public int Quantity { get; set; }
[Id(5)] public decimal UnitPrice { get; set; }
[Id(6)] public string DetailsUrl { get; set; } = null!;
[Id(7)] public string ImageUrl { get; set; } = null!;

[JsonIgnore]
public decimal TotalPrice =>
Expand Down
4 changes: 3 additions & 1 deletion samples/ShoppingCart/Grains/InventoryGrain.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT License.

using Orleans.Runtime;

namespace Orleans.ShoppingCart.Grains;

[Reentrant]
Expand All @@ -15,7 +17,7 @@ public InventoryGrain(
storageName: "shopping-cart")]
IPersistentState<HashSet<string>> state) => _productIds = state;

public override Task OnActivateAsync() => PopulateProductCacheAsync();
public override Task OnActivateAsync(CancellationToken _) => PopulateProductCacheAsync();

Task<HashSet<ProductDetails>> IInventoryGrain.GetAllProductsAsync() =>
Task.FromResult(_productCache.Values.ToHashSet());
Expand Down
10 changes: 3 additions & 7 deletions samples/ShoppingCart/Grains/Orleans.ShoppingCart.Grains.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Orleans.CodeGenerator.MSBuild" Version="3.6.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="3.6.0" />
<PackageReference Include="Microsoft.Orleans.Runtime.Abstractions" Version="3.6.0" />
<PackageReference Include="Microsoft.Orleans.Runtime" Version="7.0.0" />
<PackageReference Include="Microsoft.Orleans.Sdk" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions samples/ShoppingCart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ A canonical shopping cart sample application, built using Microsoft Orleans. Thi

## Features

- [.NET 6](https://docs.microsoft.com/dotnet/core/whats-new/dotnet-6)
- [ASP.NET Core Blazor](https://docs.microsoft.com/aspnet/core/blazor/?view=aspnetcore-6.0)
- [.NET 7](https://docs.microsoft.com/dotnet/core/whats-new/dotnet-7)
- [ASP.NET Core Blazor](https://docs.microsoft.com/aspnet/core/blazor/?view=aspnetcore-7.0)
- [Orleans: Grain persistence](https://docs.microsoft.com/dotnet/orleans/grains/grain-persistence)
- [Azure Storage grain persistence](https://docs.microsoft.com/dotnet/orleans/grains/grain-persistence/azure-storage)
- [Orleans: Cluster management](https://docs.microsoft.com/dotnet/orleans/implementation/cluster-management)
Expand All @@ -32,7 +32,7 @@ The app is architected as follows:
### Prerequisites

- A [GitHub account](https://github.com/join)
- The [.NET 6 SDK or later](https://dotnet.microsoft.com/download/dotnet)
- The [.NET 7 SDK or later](https://dotnet.microsoft.com/download/dotnet)
- The [Azure CLI](/cli/azure/install-azure-cli)
- A .NET integrated development environment (IDE)
- Feel free to use the [Visual Studio IDE](https://visualstudio.microsoft.com) or the [Visual Studio Code](https://code.visualstudio.com)
Expand Down
16 changes: 8 additions & 8 deletions samples/ShoppingCart/Silo/Orleans.ShoppingCart.Silo.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsTransformWebConfigDisabled>false</IsTransformWebConfigDisabled>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.6.0" />
<PackageReference Include="Blazor.Serialization" Version="2.0.9" />
<PackageReference Include="Blazor.LocalStorage" Version="2.0.9" />
<PackageReference Include="Azure.Identity" Version="1.8.0" />
<PackageReference Include="Blazor.Serialization" Version="2.0.11" />
<PackageReference Include="Blazor.LocalStorage" Version="2.0.11" />
<PackageReference Include="Bogus" Version="34.0.2" />
<PackageReference Include="Microsoft.Orleans.Clustering.AzureStorage" Version="3.6.2" />
<PackageReference Include="Microsoft.Orleans.Persistence.AzureStorage" Version="3.6.2" />
<PackageReference Include="Microsoft.Orleans.Server" Version="3.6.2" />
<PackageReference Include="MudBlazor" Version="6.0.9" />
<PackageReference Include="Microsoft.Orleans.Clustering.AzureStorage" Version="7.0.0" />
<PackageReference Include="Microsoft.Orleans.Persistence.AzureStorage" Version="7.0.0" />
<PackageReference Include="Microsoft.Orleans.Server" Version="7.0.0" />
<PackageReference Include="MudBlazor" Version="6.0.18" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions samples/ShoppingCart/Silo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ await Host.CreateDefaultBuilder(args)
else
{
var endpointAddress =
IPAddress.Parse(context.Configuration["WEBSITE_PRIVATE_IP"]);
IPAddress.Parse(context.Configuration["WEBSITE_PRIVATE_IP"] ?? "");
var strPorts =
context.Configuration["WEBSITE_PRIVATE_PORTS"].Split(',');
(context.Configuration["WEBSITE_PRIVATE_PORTS"] ?? "").Split(',');
if (strPorts.Length < 2)
throw new Exception("Insufficient private ports configured.");
var (siloPort, gatewayPort) =
Expand Down