Skip to content

Commit f98097e

Browse files
Merge branch 'main' into seo/94960-csharp-completedtask-fromresult-return-in-async-methods
2 parents b323c07 + 7235df4 commit f98097e

101 files changed

Lines changed: 1528 additions & 703 deletions

File tree

Some content is hidden

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

‎.github/workflows/pr-build.yml‎

Lines changed: 255 additions & 199 deletions
Large diffs are not rendered by default.

‎README.md‎

Lines changed: 160 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,171 @@
1+
<div align="center">
2+
13
# Code Maze Guides
2-
Code Maze is a blog about simplicity and pragmatism. We tend to write clear and simple articles, easily understandable by everyone.
34

4-
We run a primarily C#/.NET (Core) blog, with some accent on web development and web applications. Besides trying to implement best practices and use the newest technologies available, we are focusing on the entire lifecycle of .NET (Core) applications.
5+
**The source code for 800+ C# and .NET articles from [code-maze.com](https://code-maze.com/?source=github).**<br>Every article gets its own runnable solution, most with tests.
6+
7+
[![Stars](https://img.shields.io/github/stars/CodeMazeBlog/CodeMazeGuides?style=flat&logo=github)](https://github.com/CodeMazeBlog/CodeMazeGuides/stargazers) [![Forks](https://img.shields.io/github/forks/CodeMazeBlog/CodeMazeGuides?style=flat&logo=github)](https://github.com/CodeMazeBlog/CodeMazeGuides/network/members) [![PR Build](https://github.com/CodeMazeBlog/CodeMazeGuides/actions/workflows/pr-build.yml/badge.svg)](https://github.com/CodeMazeBlog/CodeMazeGuides/actions/workflows/pr-build.yml) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![.NET](https://img.shields.io/badge/.NET-512BD4?logo=dotnet&logoColor=white)](https://dotnet.microsoft.com/)
8+
9+
[Blog](https://code-maze.com/?source=github) · [Courses](https://courses.code-maze.com/courses/?source=github) · [YouTube](https://www.youtube.com/@CodeMaze) · [Report an issue](https://github.com/CodeMazeBlog/CodeMazeGuides/issues)
10+
11+
</div>
12+
13+
---
14+
15+
## Contents
16+
17+
- [About](#about)
18+
- [Quick start](#quick-start)
19+
- [Browse by topic](#browse-by-topic)
20+
- [Repository layout](#repository-layout)
21+
- [Contributing](#contributing)
22+
- [Support Code Maze](#support-code-maze)
23+
- [License](#license)
24+
25+
## About
26+
27+
Code Maze is a blog about C# and .NET, written with simplicity and pragmatism in mind. The articles are hands-on. They focus on the core of each topic and show working code, not theory alone.
28+
29+
This repository holds that code. If you came here from an article, the article links to its exact folder. If you are just browsing, pick a topic below.
30+
31+
## Quick start
32+
33+
You need the [.NET SDK](https://dotnet.microsoft.com/download). Each project states its target framework in its `.csproj` file, so install the version that project asks for.
34+
35+
```bash
36+
git clone https://github.com/CodeMazeBlog/CodeMazeGuides.git
37+
cd CodeMazeGuides/<topic>/<article-folder>
38+
dotnet build
39+
dotnet run
40+
dotnet test
41+
```
42+
43+
> [!TIP]
44+
> The full repository is large. To get only one article, use a sparse checkout:
45+
>
46+
> ```bash
47+
> git clone --filter=blob:none --sparse https://github.com/CodeMazeBlog/CodeMazeGuides.git
48+
> cd CodeMazeGuides
49+
> git sparse-checkout set <topic>/<article-folder>
50+
> ```
51+
52+
## Browse by topic
53+
54+
The numbers show how many article projects each folder holds.
55+
56+
### C# language
57+
58+
| Topic | Projects |
59+
| --- | ---: |
60+
| [C# basics](csharp-basic-topics) | 45 |
61+
| [C# intermediate](csharp-intermediate-topics) | 48 |
62+
| [C# advanced](csharp-advanced-topics) | 28 |
63+
| [Classes, structs and records](csharp-classes-struct-record) | 11 |
64+
| [Methods](csharp-methods) | 9 |
65+
| [Operators](csharp-operators) | 5 |
66+
| [Strings](strings-csharp) | 39 |
67+
| [Numbers](numbers-csharp) | 19 |
68+
| [LINQ](csharp-linq) | 20 |
69+
| [Async programming](async-csharp) | 11 |
70+
| [Threads](threads-csharp) | 7 |
71+
| [Exception handling](exception-handling) | 10 |
72+
| [Refactoring](csharp-refactoring) | 5 |
73+
74+
### Collections
75+
76+
| Topic | Projects |
77+
| --- | ---: |
78+
| [Collections](collections-csharp) | 24 |
79+
| [Arrays](collections-arrays) | 24 |
80+
| [Lists](collections-lists) | 16 |
81+
| [Dictionaries](collections-dictionary) | 9 |
82+
83+
### ASP.NET Core and Blazor
84+
85+
| Topic | Projects |
86+
| --- | ---: |
87+
| [ASP.NET Core Web API](aspnetcore-webapi) | 56 |
88+
| [ASP.NET Core features](aspnetcore-features) | 52 |
89+
| [Authentication and authorization](authorization-dotnet) | 23 |
90+
| [Query strings](dotnet-querystrings) | 6 |
91+
| [Blazor features](blazor-features) | 11 |
92+
| [Blazor libraries](blazor-libraries) | 2 |
93+
| [Angular](angular) | 1 |
94+
95+
### Data and serialization
96+
97+
| Topic | Projects |
98+
| --- | ---: |
99+
| [Entity Framework Core](dotnet-efcore) | 28 |
100+
| [Dapper](dotnet-dapper) | 4 |
101+
| [MongoDB](dotnet-mongo-db) | 3 |
102+
| [JSON](json-csharp) | 29 |
103+
| [XML](xml-csharp) | 6 |
104+
| [Files and streams](files-csharp) | 23 |
105+
| [Date and time](dotnet-datetime) | 22 |
106+
| [Searching](dotnet-searching) | 1 |
107+
108+
### Architecture and design
109+
110+
| Topic | Projects |
111+
| --- | ---: |
112+
| [Design patterns](csharp-design-patterns) | 12 |
113+
| [Architectural patterns](csharp-architectural-patterns) | 13 |
114+
| [Domain-driven design](domain-driven%20design) | 1 |
115+
| [Dependency injection](dotnet-dependency-injection) | 11 |
116+
| [DI tools](dependency-injection-tools) | 3 |
117+
| [Microservices](dotnet-microservices) | 2 |
118+
119+
### Libraries, tooling and operations
120+
121+
| Topic | Projects |
122+
| --- | ---: |
123+
| [Client libraries](dotnet-client-libraries) | 60 |
124+
| [Base libraries](dotnet-base-libraries) | 3 |
125+
| [Testing](dotnet-testing) | 32 |
126+
| [Logging](dotnet-logging) | 13 |
127+
| [Performance](dotnet-performance) | 9 |
128+
| [.NET CLI](dotnet-cli) | 2 |
129+
| [Visual Studio](visual-studio) | 5 |
130+
| [Deployment](dotnet-deployment) | 2 |
131+
| [Platform-specific code](dotnet-platform-specific) | 3 |
132+
| [Projects](dotnet-projects) | 13 |
133+
134+
### Algorithms, AI and more
135+
136+
| Topic | Projects |
137+
| --- | ---: |
138+
| [Algorithms](csharp-algorithms) | 13 |
139+
| [Machine learning](csharp-machine-learning) | 5 |
140+
| [AI](csharp-ai) | 1 |
141+
| [Images](csharp-images) | 3 |
142+
143+
## Repository layout
144+
145+
```text
146+
CodeMazeGuides/
147+
├── <topic>/ # one folder per topic, e.g. aspnetcore-webapi
148+
│ └── <article-folder>/ # one folder per article
149+
│ ├── <Project>.sln # its own solution
150+
│ ├── <Project>/ # the example code
151+
│ └── Tests/ # tests, in most articles
152+
└── .github/workflows/ # PR build: builds and tests changed projects
153+
```
5154
6-
We think that the combination of a hands-on approach and focusing on the essence of the topic in our articles is what makes our blog unique. Hopefully, this approach will be something that helps you learn quicker and achieve the best results possible.
155+
Each article is self-contained. You never need to build the whole repository.
7156

8-
This repository contains most of the code from our blog.
157+
## Contributing
9158

10-
The Materials
11-
==============================
12-
If you like what you've learned and would like to support us, you can check some of our materials:
159+
Found a bug in an example, or does a project not build on a newer .NET version? [Open an issue](https://github.com/CodeMazeBlog/CodeMazeGuides/issues) or send a pull request. The PR build checks every changed project automatically.
13160

14-
Here's the "Ultimate ASP.NET Core WEB API - Second Edition": <br/>
15-
**[ULTIMATE ASP.NET CORE WEB API](https://code-maze.com/ultimate-aspnetcore-webapi-second-edition/?source=github)**
161+
## Support Code Maze
16162

17-
Here's the "Blazor WebAssembly (.NET 7)" Video Course: <br/>
18-
**[BLAZOR WEBASSEMBLY VIDEO COURSE](https://code-maze.com/blazor-webassembly-course/?source=github)**
163+
The blog is free. Our courses keep it that way. If the articles helped you, have a look:
19164

20-
| Ultimate Web API | Blazor WebAssembly |
21-
| - | - |
22-
| [<img src="https://code-maze.com/wp-content/uploads/2022/08/ultimate-aspnet-core-banner-v3-690-min.webp" width="500">](https://code-maze.com/ultimate-aspnetcore-webapi-second-edition/?source=github) | [<img src="https://code-maze.com/wp-content/uploads/2021/04/banner-blog-final-min.png" width="500">](https://code-maze.com/blazor-webassembly-course/?source=github) |
165+
<a href="https://courses.code-maze.com/courses/?source=github"><strong>Browse all Code Maze courses →</strong></a>
23166

24-
We appreciate your support. It helps us provide even more free materials on the blog.
167+
A ⭐ on this repository also helps other developers find it.
25168

26-
Running the Examples
27-
================
28-
Each article is separated into its own folder on the repository and has its own solution. Whether you came from the article or just browsing the repository, each solution can be built separately with `dotnet build` or run with `dotnet run`.
169+
## License
29170

30-
On top of that, most of the solutions contain additional tests you can browse and run with `dotnet test`. Tests usually serve to verify the solution, but you can often find some useful ideas and additional examples.
171+
[MIT](LICENSE). Use the code freely in your own projects.
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<UserSecretsId>aspnet-IdentityUserExtension-41039A27-11C0-4BD1-98EF-4FF82DC4AB8A</UserSecretsId>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="7.0.7" />
12-
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.7" />
13-
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="7.0.7" />
14-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.7" />
15-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.9" />
16-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.7" />
11+
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="10.0.12" />
12+
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="10.0.12" />
13+
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="10.0.12" />
14+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.12" />
15+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.12" />
16+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.12" />
1717
</ItemGroup>
1818

1919
</Project>

aspnetcore-features/IdentityUserExtension/IdentityUserExtension/Migrations/20230719071400_CreateIdentitySchema.Designer.cs renamed to aspnetcore-features/IdentityUserExtension/IdentityUserExtension/Migrations/20260914135203_CreateIdentitySchema.Designer.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aspnetcore-features/IdentityUserExtension/IdentityUserExtension/Migrations/20230719071400_CreateIdentitySchema.cs renamed to aspnetcore-features/IdentityUserExtension/IdentityUserExtension/Migrations/20260914135203_CreateIdentitySchema.cs

File renamed without changes.

‎aspnetcore-features/IdentityUserExtension/IdentityUserExtension/Migrations/ApplicationDbContextModelSnapshot.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
1717
{
1818
#pragma warning disable 612, 618
1919
modelBuilder
20-
.HasAnnotation("ProductVersion", "7.0.9")
20+
.HasAnnotation("ProductVersion", "10.0.12")
2121
.HasAnnotation("Relational:MaxIdentifierLength", 128);
2222

2323
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

‎aspnetcore-features/IdentityUserExtension/IdentityUserExtension/Models/ApplicationUser.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace IdentityUserExtension.Models;
44

55
public class ApplicationUser : IdentityUser<Guid>
66
{
7-
public string DisplayName { get; set; }
7+
public required string DisplayName { get; set; }
88
public DateTime LastLoginDateTime { get; set; }
9-
public List<Post> Posts { get; set; }
9+
public List<Post> Posts { get; set; } = [];
1010
}

‎aspnetcore-features/IdentityUserExtension/IdentityUserExtension/Models/Post.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ namespace IdentityUserExtension.Models;
33
public class Post
44
{
55
public Guid Id { get; set; }
6-
public string Title { get; set; }
7-
public string Text { get; set; }
6+
public required string Title { get; set; }
7+
public required string Text { get; set; }
88
}

‎aspnetcore-features/IdentityUserExtension/IdentityUserExtension/Program.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Microsoft.AspNetCore.Identity;
12
using Microsoft.EntityFrameworkCore;
23
using IdentityUserExtension.Data;
34
using IdentityUserExtension.Models;
@@ -11,6 +12,7 @@
1112
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
1213

1314
builder.Services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
15+
.AddRoles<IdentityRole<Guid>>()
1416
.AddEntityFrameworkStores<ApplicationDbContext>();
1517
builder.Services.AddControllersWithViews();
1618

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Security.Claims;
2+
using IdentityUserExtension.Models;
3+
using Microsoft.AspNetCore.Identity;
4+
5+
namespace IdentityUserExtension.Services;
6+
7+
public class UserProfileService
8+
{
9+
private readonly UserManager<ApplicationUser> _userManager;
10+
11+
public UserProfileService(UserManager<ApplicationUser> userManager)
12+
{
13+
_userManager = userManager;
14+
}
15+
16+
public async Task<IdentityResult> RecordSignIn(ClaimsPrincipal principal)
17+
{
18+
var user = await _userManager.GetUserAsync(principal);
19+
if (user is null)
20+
{
21+
return IdentityResult.Failed();
22+
}
23+
24+
user.LastLoginDateTime = DateTime.UtcNow;
25+
26+
return await _userManager.UpdateAsync(user);
27+
}
28+
}

0 commit comments

Comments
 (0)