Skip to content

Commit 2d0bb1d

Browse files
committed
initial commit
0 parents  commit 2d0bb1d

18 files changed

+1121
-0
lines changed

.gitignore

Lines changed: 484 additions & 0 deletions
Large diffs are not rendered by default.

.vscode/launch.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Debug: Minimal API (Swagger)",
6+
"type": "coreclr",
7+
"request": "launch",
8+
"program": "${workspaceFolder}/src/backend/Players.API/bin/Debug/net8.0/Players.API.dll",
9+
"serverReadyAction": {
10+
"action": "openExternally",
11+
"pattern": "\\bNow listening on:\\s+https://localhost:([0-9]+)",
12+
"uriFormat": "https://localhost:%s/swagger"
13+
},
14+
"env": {
15+
"ASPNETCORE_ENVIRONMENT": "Development",
16+
"ASPNETCORE_URLS": "https://localhost:9000",
17+
"ASPNETCORE_DETAILEDERRORS": "1",
18+
"ASPNETCORE_SHUTDOWNTIMEOUTSECONDS": "3"
19+
}
20+
},
21+
{
22+
"name": "Attach: Minimal API",
23+
"type": "coreclr",
24+
"request": "attach",
25+
"processId": "${command:pickProcess}"
26+
}
27+
]
28+
}

.vscode/settings.json

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"workbench.editor.decorations.colors": true,
3+
"workbench.editor.wrapTabs": true,
4+
"workbench.editor.pinnedTabsOnSeparateRow": true,
5+
"workbench.editor.pinnedTabSizing": "shrink",
6+
"workbench.startupEditor": "none",
7+
"workbench.tree.indent": 11,
8+
"workbench.tree.renderIndentGuides": "always",
9+
"workbench.colorTheme": "GitHub Dark",
10+
"workbench.iconTheme": "material-icon-theme",
11+
"workbench.colorCustomizations": {
12+
"tree.indentGuidesStroke": "#999999",
13+
"[Material Theme Darker High Contrast]": {}
14+
},
15+
"workbench.tree.enableStickyScroll": true,
16+
17+
"editor.rulers": [{ "column": 127 }],
18+
"editor.tabSize": 4,
19+
"editor.insertSpaces": true,
20+
"editor.trimAutoWhitespace": true,
21+
"editor.renderWhitespace": "boundary",
22+
"editor.wordWrap": "off",
23+
"editor.bracketPairColorization.enabled": true,
24+
"editor.guides.bracketPairs": "active",
25+
"editor.largeFileOptimizations": false,
26+
"editor.stickyScroll.enabled": true,
27+
"editor.minimap.enabled": true,
28+
"editor.minimap.showSlider": "always",
29+
"editor.minimap.maxColumn": 127,
30+
"editor.minimap.renderCharacters": false,
31+
"editor.minimap.size": "fill",
32+
"editor.cursorStyle": "block",
33+
"editor.cursorBlinking": "smooth",
34+
"editor.cursorSmoothCaretAnimation": "on",
35+
36+
"files.trimTrailingWhitespace": true,
37+
"files.insertFinalNewline": true,
38+
"files.trimFinalNewlines": true,
39+
"files.autoGuessEncoding": true,
40+
41+
"breadcrumbs.enabled": true,
42+
"explorer.autoReveal": true,
43+
"explorer.compactFolders": false,
44+
"window.density.editorTabHeight": "compact",
45+
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
46+
"markdown-preview-github-styles.darkTheme": "light",
47+
"terminal.integrated.fontFamily": "Menlo for Powerline",
48+
"debug.toolBarLocation": "commandCenter",
49+
50+
"git.autofetch": true,
51+
"git.autoStash": true,
52+
"git.mergeEditor": true,
53+
"git.defaultBranchName": "master",
54+
"git.branchProtection": ["master"],
55+
"git.pruneOnFetch": false,
56+
"github.branchProtection": true,
57+
"githubPullRequests.pullBranch": "never",
58+
"diffEditor.ignoreTrimWhitespace": false,
59+
60+
"[csharp]": {
61+
"editor.formatOnSave": true,
62+
"editor.defaultFormatter": "ms-dotnettools.csharp"
63+
},
64+
65+
"[json]": {
66+
"editor.formatOnSave": true,
67+
"editor.tabSize": 2,
68+
"editor.defaultFormatter": "esbenp.prettier-vscode"
69+
},
70+
"json.maxItemsComputed": 99999,
71+
72+
"testing.alwaysRevealTestOnStateChange": true
73+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3236F42E-2310-44BA-B786-90F0B6069153}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlayersApi", "src\PlayersApi\PlayersApi.csproj", "{805FA9B9-3D63-4AAD-9633-DC07CC2135AD}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(SolutionProperties) = preSolution
16+
HideSolutionNode = FALSE
17+
EndGlobalSection
18+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
19+
{805FA9B9-3D63-4AAD-9633-DC07CC2135AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20+
{805FA9B9-3D63-4AAD-9633-DC07CC2135AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
21+
{805FA9B9-3D63-4AAD-9633-DC07CC2135AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
22+
{805FA9B9-3D63-4AAD-9633-DC07CC2135AD}.Release|Any CPU.Build.0 = Release|Any CPU
23+
EndGlobalSection
24+
GlobalSection(NestedProjects) = preSolution
25+
{805FA9B9-3D63-4AAD-9633-DC07CC2135AD} = {3236F42E-2310-44BA-B786-90F0B6069153}
26+
EndGlobalSection
27+
EndGlobal

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Nano Taboada
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# 🧪 Minimal API with ASP.NET Core
2+
3+
## Manifesto
4+
5+
> "Nobody should start to undertake a large project. You start with a small _trivial_ project, and you should never expect it to get large. If you do, you'll just overdesign and generally think it is more important than it likely is at that stage. Or worse, you might be scared away by the sheer size of the work you envision. So start small, and think about the details. Don't think about some big picture and fancy design. If it doesn't solve some fairly immediate need, it's almost certainly over-designed. And don't expect people to jump in and help you. That's not how these things work. You need to get something half-way _useful_ first, and then others will say "hey, that _almost_ works for me", and they'll get involved in the project." — Linus Torvalds
6+
7+
## About
8+
9+
Proof of Concept for a [Minimal API](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis?view=aspnetcore-8.0), made with [ASP.NET Core 8.0](https://learn.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-8.0?view=aspnetcore-8.0), targeting [.NET 8](https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-8), inspired by the official [Tutorial: Create a minimal web API with ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/tutorials/min-web-api?view=aspnetcore-8.0&tabs=visual-studio-code).
10+
11+
## Credits
12+
13+
- The solution has been coded using [Visual Studio Code](https://code.visualstudio.com/).
14+
- AI assistance provided by [Gemini](https://gemini.google.com/) and [Copilot](https://copilot.microsoft.com/).
15+
16+
## Terms
17+
18+
All trademarks, registered trademarks, service marks, product names, company names, or logos mentioned on this repository are the property of their respective owners. All usage of such terms herein is for identification purposes only and constitutes neither an endorsement nor a recommendation of those items. Furthermore, the use of such terms is intended to be for educational and informational purposes only.

src/PlayersApi/Data/PlayerData.cs

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
namespace Dotnet.Samples.AspNetCore.MinimalApi;
2+
3+
public static class PlayerData
4+
{
5+
public static List<Player> CreateStarting11()
6+
{
7+
return
8+
[
9+
new()
10+
{
11+
Id = 1,
12+
FirstName = "Damián",
13+
MiddleName = "Emiliano",
14+
LastName = "Martínez",
15+
DateOfBirth = new DateTime(1992, 9, 1, 0, 0, 0, DateTimeKind.Utc),
16+
SquadNumber = 23,
17+
Position = "Goalkeeper",
18+
AbbrPosition = "GK",
19+
Team = "Aston Villa FC",
20+
League = "Premier League",
21+
Starting11 = true,
22+
},
23+
new()
24+
{
25+
Id = 2,
26+
FirstName = "Nahuel",
27+
LastName = "Molina",
28+
DateOfBirth = new DateTime(1998, 4, 5, 0, 0, 0, DateTimeKind.Utc),
29+
SquadNumber = 26,
30+
Position = "Right-Back",
31+
AbbrPosition = "RB",
32+
Team = "Altético Madrid",
33+
League = "La Liga",
34+
Starting11 = true,
35+
},
36+
new()
37+
{
38+
Id = 3,
39+
FirstName = "Cristian",
40+
MiddleName = "Gabriel",
41+
LastName = "Romero",
42+
DateOfBirth = new DateTime(1998, 4, 26, 0, 0, 0, DateTimeKind.Utc),
43+
SquadNumber = 13,
44+
Position = "Centre-Back",
45+
AbbrPosition = "CB",
46+
Team = "Tottenham Hotspur",
47+
League = "Premier League",
48+
Starting11 = true,
49+
},
50+
new()
51+
{
52+
Id = 4,
53+
FirstName = "Nicolás",
54+
MiddleName = "Hernán Gonzalo",
55+
LastName = "Otamendi",
56+
DateOfBirth = new DateTime(1988, 2, 11, 0, 0, 0, DateTimeKind.Utc),
57+
SquadNumber = 19,
58+
Position = "Centre-Back",
59+
AbbrPosition = "CB",
60+
Team = "SL Benfica",
61+
League = "Liga Portugal",
62+
Starting11 = true,
63+
},
64+
new()
65+
{
66+
Id = 5,
67+
FirstName = "Nicolás",
68+
MiddleName = "Alejandro",
69+
LastName = "Tagliafico",
70+
DateOfBirth = new DateTime(1992, 8, 30, 0, 0, 0, DateTimeKind.Utc),
71+
SquadNumber = 3,
72+
Position = "Left-Back",
73+
AbbrPosition = "LB",
74+
Team = "Olympique Lyon",
75+
League = "Ligue 1",
76+
Starting11 = true,
77+
},
78+
new()
79+
{
80+
Id = 6,
81+
FirstName = "Ángel",
82+
MiddleName = "Fabián",
83+
LastName = "Di María",
84+
DateOfBirth = new DateTime(1988, 2, 13, 0, 0, 0, DateTimeKind.Utc),
85+
SquadNumber = 11,
86+
Position = "Right Winger",
87+
AbbrPosition = "RW",
88+
Team = "SL Benfica",
89+
League = "Liga Portugal",
90+
Starting11 = true,
91+
},
92+
new()
93+
{
94+
Id = 7,
95+
FirstName = "Rodrigo",
96+
MiddleName = "Javier",
97+
LastName = "de Paul",
98+
DateOfBirth = new DateTime(1994, 5, 23, 0, 0, 0, DateTimeKind.Utc),
99+
SquadNumber = 7,
100+
Position = "Central Midfield",
101+
AbbrPosition = "CM",
102+
Team = "Altético Madrid",
103+
League = "La Liga",
104+
Starting11 = true,
105+
},
106+
new()
107+
{
108+
Id = 8,
109+
FirstName = "Enzo",
110+
MiddleName = "Jeremías",
111+
LastName = "Fernández",
112+
DateOfBirth = new DateTime(2001, 1, 16, 0, 0, 0, DateTimeKind.Utc),
113+
SquadNumber = 24,
114+
Position = "Central Midfield",
115+
AbbrPosition = "CM",
116+
Team = "Chelsea FC",
117+
League = "Premier League",
118+
Starting11 = true,
119+
},
120+
new()
121+
{
122+
Id = 9,
123+
FirstName = "Alexis",
124+
LastName = "Mac Allister",
125+
DateOfBirth = new DateTime(1998, 12, 23, 0, 0, 0, DateTimeKind.Utc),
126+
SquadNumber = 20,
127+
Position = "Central Midfield",
128+
AbbrPosition = "CM",
129+
Team = "Liverpool FC",
130+
League = "Premier League",
131+
Starting11 = true,
132+
},
133+
new()
134+
{
135+
Id = 10,
136+
FirstName = "Lionel",
137+
MiddleName = "Andrés",
138+
LastName = "Messi",
139+
DateOfBirth = new DateTime(1987, 6, 23, 0, 0, 0, DateTimeKind.Utc),
140+
SquadNumber = 10,
141+
Position = "Right Winger",
142+
AbbrPosition = "RW",
143+
Team = "Inter Miami CF",
144+
League = "Major League Soccer",
145+
Starting11 = true,
146+
},
147+
new()
148+
{
149+
Id = 11,
150+
FirstName = "Julián",
151+
LastName = "Álvarez",
152+
DateOfBirth = new DateTime(2000, 1, 30, 0, 0, 0, DateTimeKind.Utc),
153+
SquadNumber = 9,
154+
Position = "Centre-Forward",
155+
AbbrPosition = "CF",
156+
Team = "Manchester City",
157+
League = "Premier League",
158+
Starting11 = true,
159+
}
160+
];
161+
}
162+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace Dotnet.Samples.AspNetCore.MinimalApi;
2+
3+
public static class PlayerDataExtensions
4+
{
5+
public static void MapFrom(this Player target, Player source)
6+
{
7+
target.FirstName = source.FirstName;
8+
target.MiddleName = source.MiddleName;
9+
target.LastName = source.LastName;
10+
target.DateOfBirth = source.DateOfBirth;
11+
target.SquadNumber = source.SquadNumber;
12+
target.Position = source.Position;
13+
target.AbbrPosition = source.AbbrPosition;
14+
target.Team = source.Team;
15+
target.League = source.League;
16+
target.Starting11 = source.Starting11;
17+
}
18+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Dotnet.Samples.AspNetCore.MinimalApi;
2+
3+
using Microsoft.EntityFrameworkCore;
4+
5+
public class PlayerDbContext : DbContext
6+
{
7+
public PlayerDbContext(DbContextOptions<PlayerDbContext> options)
8+
: base(options) { }
9+
10+
public DbSet<Player> Players => Set<Player>();
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Dotnet.Samples.AspNetCore.MinimalApi;
2+
3+
public static class PlayerDbContextExtensions
4+
{
5+
public static void Seed(this PlayerDbContext context)
6+
{
7+
if (!context.Players.Any())
8+
{
9+
context.Players.AddRange(PlayerData.CreateStarting11());
10+
11+
context.SaveChanges();
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)