Skip to content

Commit 2c28378

Browse files
authored
Upgrade to .NET 6 (#330)
1 parent 4c8cb74 commit 2c28378

File tree

576 files changed

+24696
-7610
lines changed

Some content is hidden

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

576 files changed

+24696
-7610
lines changed

.editorconfig

+189
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# Rules in this file were initially inferred by Visual Studio IntelliCode from the C:\dev\dnp\blazor-workshop\src codebase based on best match to current usage at 3/28/2022
2+
# You can modify the rules from these initially generated values to suit your own policies
3+
# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference
4+
[*.cs]
5+
6+
7+
#Formatting - new line options
8+
9+
#place catch statements on a new line
10+
csharp_new_line_before_catch = true
11+
#place else statements on a new line
12+
csharp_new_line_before_else = true
13+
#require members of anonymous types to be on separate lines
14+
csharp_new_line_before_members_in_anonymous_types = true
15+
#require members of object intializers to be on separate lines
16+
csharp_new_line_before_members_in_object_initializers = true
17+
#require braces to be on a new line for methods, control_blocks, types, object_collection_array_initializers, and anonymous_types (also known as "Allman" style)
18+
csharp_new_line_before_open_brace = methods, control_blocks, types, object_collection_array_initializers, anonymous_types
19+
20+
#Formatting - organize using options
21+
22+
#sort System.* using directives alphabetically, and place them before other usings
23+
dotnet_sort_system_directives_first = true
24+
25+
#Formatting - spacing options
26+
27+
#require NO space between a cast and the value
28+
csharp_space_after_cast = false
29+
#require a space before the colon for bases or interfaces in a type declaration
30+
csharp_space_after_colon_in_inheritance_clause = true
31+
#require a space after a keyword in a control flow statement such as a for loop
32+
csharp_space_after_keywords_in_control_flow_statements = true
33+
#require a space before the colon for bases or interfaces in a type declaration
34+
csharp_space_before_colon_in_inheritance_clause = true
35+
#remove space within empty argument list parentheses
36+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
37+
#remove space between method call name and opening parenthesis
38+
csharp_space_between_method_call_name_and_opening_parenthesis = false
39+
#do not place space characters after the opening parenthesis and before the closing parenthesis of a method call
40+
csharp_space_between_method_call_parameter_list_parentheses = false
41+
#remove space within empty parameter list parentheses for a method declaration
42+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
43+
#place a space character after the opening parenthesis and before the closing parenthesis of a method declaration parameter list.
44+
csharp_space_between_method_declaration_parameter_list_parentheses = false
45+
46+
#Formatting - wrapping options
47+
48+
#leave code block on single line
49+
csharp_preserve_single_line_blocks = true
50+
51+
#Style - Code block preferences
52+
53+
#prefer curly braces even for one line of code
54+
csharp_prefer_braces = true:suggestion
55+
56+
#Style - expression bodied member options
57+
58+
#prefer block bodies for constructors
59+
csharp_style_expression_bodied_constructors = false:suggestion
60+
#prefer block bodies for methods
61+
csharp_style_expression_bodied_methods = false:suggestion
62+
#prefer expression-bodied members for properties
63+
csharp_style_expression_bodied_properties = true:suggestion
64+
65+
#Style - expression level options
66+
67+
#prefer ItemX properties to tuple names
68+
dotnet_style_explicit_tuple_names = false:suggestion
69+
#prefer the language keyword for member access expressions, instead of the type name, for types that have a keyword to represent them
70+
dotnet_style_predefined_type_for_member_access = true:suggestion
71+
72+
#Style - Expression-level preferences
73+
74+
#prefer objects to be initialized using object initializers when possible
75+
dotnet_style_object_initializer = true:suggestion
76+
#prefer inferred anonymous type member names
77+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
78+
#prefer inferred tuple element names
79+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
80+
81+
#Style - implicit and explicit types
82+
83+
#prefer var over explicit type in all cases, unless overridden by another code style rule
84+
csharp_style_var_elsewhere = true:suggestion
85+
#prefer var is used to declare variables with built-in system types such as int
86+
csharp_style_var_for_built_in_types = true:suggestion
87+
#prefer var when the type is already mentioned on the right-hand side of a declaration expression
88+
csharp_style_var_when_type_is_apparent = true:suggestion
89+
90+
#Style - language keyword and framework type options
91+
92+
#prefer the language keyword for local variables, method parameters, and class members, instead of the type name, for types that have a keyword to represent them
93+
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
94+
95+
#Style - modifier options
96+
97+
#prefer accessibility modifiers to be declared except for public interface members. This will currently not differ from always and will act as future proofing for if C# adds default interface methods.
98+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
99+
100+
#Style - Modifier preferences
101+
102+
#when this rule is set to a list of modifiers, prefer the specified ordering.
103+
csharp_preferred_modifier_order = public,private,protected,static,async,readonly,override:suggestion
104+
105+
#Style - qualification options
106+
107+
#prefer fields not to be prefaced with this. or Me. in Visual Basic
108+
dotnet_style_qualification_for_field = false:suggestion
109+
#prefer methods not to be prefaced with this. or Me. in Visual Basic
110+
dotnet_style_qualification_for_method = false:suggestion
111+
#prefer properties not to be prefaced with this. or Me. in Visual Basic
112+
dotnet_style_qualification_for_property = false:suggestion
113+
csharp_using_directive_placement = outside_namespace:silent
114+
csharp_prefer_simple_using_statement = true:suggestion
115+
csharp_style_namespace_declarations = block_scoped:silent
116+
csharp_style_prefer_method_group_conversion = true:silent
117+
csharp_style_expression_bodied_operators = false:silent
118+
csharp_style_expression_bodied_indexers = true:silent
119+
csharp_style_expression_bodied_accessors = true:silent
120+
csharp_style_expression_bodied_lambdas = true:silent
121+
csharp_style_expression_bodied_local_functions = false:silent
122+
csharp_indent_labels = one_less_than_current
123+
124+
[*.{cs,vb}]
125+
#### Naming styles ####
126+
127+
# Naming rules
128+
129+
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
130+
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
131+
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
132+
133+
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
134+
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
135+
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
136+
137+
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
138+
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
139+
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
140+
141+
# Symbol specifications
142+
143+
dotnet_naming_symbols.interface.applicable_kinds = interface
144+
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
145+
dotnet_naming_symbols.interface.required_modifiers =
146+
147+
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
148+
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
149+
dotnet_naming_symbols.types.required_modifiers =
150+
151+
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
152+
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
153+
dotnet_naming_symbols.non_field_members.required_modifiers =
154+
155+
# Naming styles
156+
157+
dotnet_naming_style.begins_with_i.required_prefix = I
158+
dotnet_naming_style.begins_with_i.required_suffix =
159+
dotnet_naming_style.begins_with_i.word_separator =
160+
dotnet_naming_style.begins_with_i.capitalization = pascal_case
161+
162+
dotnet_naming_style.pascal_case.required_prefix =
163+
dotnet_naming_style.pascal_case.required_suffix =
164+
dotnet_naming_style.pascal_case.word_separator =
165+
dotnet_naming_style.pascal_case.capitalization = pascal_case
166+
167+
dotnet_naming_style.pascal_case.required_prefix =
168+
dotnet_naming_style.pascal_case.required_suffix =
169+
dotnet_naming_style.pascal_case.word_separator =
170+
dotnet_naming_style.pascal_case.capitalization = pascal_case
171+
dotnet_style_coalesce_expression = true:suggestion
172+
dotnet_style_null_propagation = true:suggestion
173+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
174+
dotnet_style_prefer_auto_properties = true:silent
175+
dotnet_style_object_initializer = true:suggestion
176+
dotnet_style_collection_initializer = true:suggestion
177+
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
178+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
179+
dotnet_style_prefer_conditional_expression_over_return = true:silent
180+
dotnet_style_explicit_tuple_names = false:suggestion
181+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
182+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
183+
dotnet_style_prefer_compound_assignment = true:suggestion
184+
dotnet_style_operator_placement_when_wrapping = beginning_of_line
185+
indent_style = space
186+
tab_width = 4
187+
indent_size = 4
188+
end_of_line = crlf
189+
dotnet_style_prefer_simplified_interpolation = true:suggestion

Directory.Build.props

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<Project>
22
<PropertyGroup>
3-
<AspNetCoreVersion>5.0.0</AspNetCoreVersion>
4-
<BlazorVersion>5.0.0</BlazorVersion>
5-
<EntityFrameworkVersion>5.0.0</EntityFrameworkVersion>
6-
<SystemNetHttpJsonVersion>5.0.0</SystemNetHttpJsonVersion>
3+
<AspNetCoreVersion>6.0.0</AspNetCoreVersion>
4+
<BlazorVersion>6.0.0</BlazorVersion>
5+
<EntityFrameworkVersion>6.0.0</EntityFrameworkVersion>
6+
<TargetFrameworkVersion>net6.0</TargetFrameworkVersion>
7+
<SystemNetHttpJsonVersion>6.0.0</SystemNetHttpJsonVersion>
78
</PropertyGroup>
89
</Project>

docs/03-show-order-status.md

+20
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,26 @@ Now when you run the app, you'll be able to visit this page:
5656

5757
Also notice that this time, no full-page load occurs when you navigate, because the URL is matched entirely within the client-side SPA. As such, navigation is instantaneous.
5858

59+
## Adding a page title
60+
61+
In your browser, the title of the new page is listed as **Blazing Pizza** and it would be nice to update the title to reflect that this is the 'My Orders' page. We can use the new `PageTitle` component to update the title from the `MyOrders.razor` page:
62+
63+
```html
64+
@page "/myorders"
65+
66+
<PageTitle>Blazing Pizza - My Orders</PageTitle>
67+
68+
<div class="main">
69+
My orders will go here
70+
</div>
71+
```
72+
73+
This works because inside the `Program.cs` file is an entry that adds a `HeadOutlet` component to the HTML presenting the BlazingPizza application. Blazor uses this `HeadOutlet` to write content into the header of the HTML page.
74+
75+
```csharp
76+
builder.RootComponents.Add<HeadOutlet>("head::after");
77+
```
78+
5979
## Highlighting navigation position
6080

6181
Look closely at the top bar. Notice that when you're on "My orders", the link *isn't* highlighted in yellow. How can we highlight links when the user is on them? By using a `NavLink` component instead of a plain `<a>` tag. The only special thing a `NavLink` component does is toggle its own `active` CSS class depending on whether its `href` matches the current navigation state.

docs/05-checkout-with-validation.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ It's time to fix this by adding a "checkout" screen that requires customers to e
99
Start by adding a new page component, `Checkout.razor`, with a `@page` directive matching the URL `/checkout`. For the initial markup, let's display the details of the order using your `OrderReview` component:
1010

1111
```razor
12+
<PageTitle>Blazing Pizza - Checkout</PageTitle>
13+
1214
<div class="main">
1315
<div class="checkout-cols">
1416
<div class="checkout-order-details">

docs/06-authentication-and-authorization.md

+42
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,48 @@ builder.Services.AddHttpClient<OrdersClient>(client => client.BaseAddress = new
263263
.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();
264264
```
265265

266+
### Optional: Optimize JSON interactions with .NET 6 JSON CodeGeneration
267+
268+
Starting with .NET 6, the System.Text.Json.JsonSerializer supports working with optimized code generated for serializing and deserializing JSON payloads. Code is generated at build time, resulting in a significant performance improvement for the serialization and deserialization of JSON data. This is configured by taking the following steps:
269+
270+
1. Create a partial Context class that inherits from `System.Text.Json.Serialization.JsonSerializerContext`
271+
2. Decorate the class with the `System.Text.Json.JsonSourceGenerationOptions` attribute
272+
3. Add `JsonSerializable` attributes to the class definition for each type that you would like to have code generated
273+
274+
We have already written this context for you and it is located in the `BlazingPizza.Shared.Order.cs" file
275+
276+
```csharp
277+
[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)]
278+
[JsonSerializable(typeof(Order))]
279+
[JsonSerializable(typeof(OrderWithStatus))]
280+
[JsonSerializable(typeof(List<OrderWithStatus>))]
281+
[JsonSerializable(typeof(Pizza))]
282+
[JsonSerializable(typeof(List<PizzaSpecial>))]
283+
[JsonSerializable(typeof(List<Topping>))]
284+
[JsonSerializable(typeof(Topping))]
285+
public partial class OrderContext : JsonSerializerContext {}
286+
```
287+
288+
You can now optimize the calls to the HttpClient in the `OrdersClient` class by passing an `OrderContext.Default` parameter pointing to the type sought as the second parameter. Updating the methods in the `OrdersClient` class should look like the following:
289+
290+
```csharp
291+
public async Task<IEnumerable<OrderWithStatus>> GetOrders() =>
292+
await httpClient.GetFromJsonAsync("orders", OrderContext.Default.ListOrderWithStatus);
293+
294+
public async Task<OrderWithStatus> GetOrder(int orderId) =>
295+
await httpClient.GetFromJsonAsync($"orders/{orderId}", OrderContext.Default.OrderWithStatus);
296+
297+
public async Task<int> PlaceOrder(Order order)
298+
{
299+
var response = await httpClient.PostAsJsonAsync("orders", order, OrderContext.Default.Order);
300+
response.EnsureSuccessStatusCode();
301+
var orderId = await response.Content.ReadFromJsonAsync<int>();
302+
return orderId;
303+
}
304+
```
305+
306+
### Deploy OrdersClient to pages
307+
266308
Update each page where an `HttpClient` is used to manage orders to use the new typed `OrdersClient`. Inject an `OrdersClient` instead of an `HttpClient` and use the new client to make the API call. Wrap each call in a `try-catch` that handles exceptions of type `AccessTokenNotAvailableException` by calling the provided `Redirect()` method.
267309

268310
*Checkout.razor*

src/nuget.config nuget.config

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<configuration>
3-
<packageSources>
4-
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
5-
<clear />
6-
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
7-
</packageSources>
8-
</configuration>
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
5+
<clear />
6+
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
7+
</packageSources>
8+
</configuration>

save-points/00-get-started/BlazingPizza.Client/BlazingPizza.Client.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
22

33
<PropertyGroup>
4-
<TargetFramework>net5.0</TargetFramework>
4+
<TargetFramework>$(TargetFrameworkVersion)</TargetFramework>
5+
<ImplicitUsings>true</ImplicitUsings>
56
</PropertyGroup>
67

78
<ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
1-
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
2-
using Microsoft.Extensions.DependencyInjection;
3-
using System;
4-
using System.Net.Http;
5-
using System.Threading.Tasks;
1+
using BlazingPizza.Client;
2+
using Microsoft.AspNetCore.Components.Web;
3+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
64

7-
namespace BlazingPizza.Client
8-
{
9-
public class Program
10-
{
11-
public static async Task Main(string[] args)
12-
{
13-
var builder = WebAssemblyHostBuilder.CreateDefault(args);
14-
builder.RootComponents.Add<App>("#app");
5+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
6+
builder.RootComponents.Add<App>("#app");
7+
builder.RootComponents.Add<HeadOutlet>("head::after");
158

16-
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
9+
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
1710

18-
await builder.Build().RunAsync();
19-
}
20-
}
21-
}
11+
await builder.Build().RunAsync();

save-points/00-get-started/BlazingPizza.ComponentsLibrary/BlazingPizza.ComponentsLibrary.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<TargetFramework>net5.0</TargetFramework>
4+
<TargetFramework>$(TargetFrameworkVersion)</TargetFramework>
5+
<ImplicitUsings>true</ImplicitUsings>
56
</PropertyGroup>
67

78
<ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
using Microsoft.JSInterop;
2-
using System.Threading.Tasks;
32

4-
namespace BlazingPizza.ComponentsLibrary
3+
namespace BlazingPizza.ComponentsLibrary;
4+
5+
public static class LocalStorage
56
{
6-
public static class LocalStorage
7-
{
8-
public static ValueTask<T> GetAsync<T>(IJSRuntime jsRuntime, string key)
9-
=> jsRuntime.InvokeAsync<T>("blazorLocalStorage.get", key);
7+
public static ValueTask<T> GetAsync<T>(IJSRuntime jsRuntime, string key)
8+
=> jsRuntime.InvokeAsync<T>("blazorLocalStorage.get", key);
109

11-
public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value)
12-
=> jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value);
10+
public static ValueTask SetAsync(IJSRuntime jsRuntime, string key, object value)
11+
=> jsRuntime.InvokeVoidAsync("blazorLocalStorage.set", key, value);
1312

14-
public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key)
15-
=> jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key);
16-
}
13+
public static ValueTask DeleteAsync(IJSRuntime jsRuntime, string key)
14+
=> jsRuntime.InvokeVoidAsync("blazorLocalStorage.delete", key);
1715
}

0 commit comments

Comments
 (0)