├── .github
└── workflows
│ └── main.yml
├── .gitignore
├── .vscode
├── launch.json
└── tasks.json
├── Data
└── Migrations
│ ├── 20211111034925_InitialMigrations.Designer.cs
│ ├── 20211111034925_InitialMigrations.cs
│ └── TodoDbContextModelSnapshot.cs
├── MinimalApi.csproj
├── MinimalApi.sln
├── Program.cs
├── Properties
└── launchSettings.json
├── README.md
├── appsettings.Development.json
└── appsettings.json
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | # This is a basic workflow to help you get started with Actions
2 |
3 | name: CI
4 |
5 | # Controls when the workflow will run
6 | on:
7 | # Triggers the workflow on push or pull request events but only for the main branch
8 | push:
9 | branches: [ main ]
10 | pull_request:
11 | branches: [ main ]
12 |
13 | # Allows you to run this workflow manually from the Actions tab
14 | workflow_dispatch:
15 |
16 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel
17 | jobs:
18 | # This workflow contains a single job called "build"
19 | build:
20 | # The type of runner that the job will run on
21 | runs-on: ubuntu-latest
22 |
23 | # Steps represent a sequence of tasks that will be executed as part of the job
24 | steps:
25 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
26 | - uses: actions/checkout@v2
27 |
28 | - name: Set up .NET Core
29 | uses: actions/setup-dotnet@v1
30 | with:
31 | dotnet-version: '6.0.x'
32 | include-prerelease: true
33 | - name: Build with dotnet
34 | run: dotnet build --configuration Release
35 | - name: Install EF Tool
36 | run: |
37 | dotnet new tool-manifest
38 | dotnet tool install dotnet-ef
39 | - name: Build dotnet bundle
40 | run: dotnet ef migrations bundle --verbose
41 | - name: Deploy the Database Changes
42 | # The bundle command will fail because it is pointing to my local development machine.
43 | run: ./efbundle --connection ${{ secrets.CONNECTIONSTRING }}
44 |
45 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Ll]og/
33 | [Ll]ogs/
34 |
35 | # Visual Studio 2015/2017 cache/options directory
36 | .vs/
37 | # Uncomment if you have tasks that create the project's static files in wwwroot
38 | #wwwroot/
39 |
40 | # Visual Studio 2017 auto generated files
41 | Generated\ Files/
42 |
43 | # MSTest test Results
44 | [Tt]est[Rr]esult*/
45 | [Bb]uild[Ll]og.*
46 |
47 | # NUnit
48 | *.VisualState.xml
49 | TestResult.xml
50 | nunit-*.xml
51 |
52 | # Build Results of an ATL Project
53 | [Dd]ebugPS/
54 | [Rr]eleasePS/
55 | dlldata.c
56 |
57 | # Benchmark Results
58 | BenchmarkDotNet.Artifacts/
59 |
60 | # .NET Core
61 | project.lock.json
62 | project.fragment.lock.json
63 | artifacts/
64 |
65 | # Tye
66 | .tye/
67 |
68 | # ASP.NET Scaffolding
69 | ScaffoldingReadMe.txt
70 |
71 | # StyleCop
72 | StyleCopReport.xml
73 |
74 | # Files built by Visual Studio
75 | *_i.c
76 | *_p.c
77 | *_h.h
78 | *.ilk
79 | *.meta
80 | *.obj
81 | *.iobj
82 | *.pch
83 | *.pdb
84 | *.ipdb
85 | *.pgc
86 | *.pgd
87 | *.rsp
88 | *.sbr
89 | *.tlb
90 | *.tli
91 | *.tlh
92 | *.tmp
93 | *.tmp_proj
94 | *_wpftmp.csproj
95 | *.log
96 | *.vspscc
97 | *.vssscc
98 | .builds
99 | *.pidb
100 | *.svclog
101 | *.scc
102 |
103 | # Chutzpah Test files
104 | _Chutzpah*
105 |
106 | # Visual C++ cache files
107 | ipch/
108 | *.aps
109 | *.ncb
110 | *.opendb
111 | *.opensdf
112 | *.sdf
113 | *.cachefile
114 | *.VC.db
115 | *.VC.VC.opendb
116 |
117 | # Visual Studio profiler
118 | *.psess
119 | *.vsp
120 | *.vspx
121 | *.sap
122 |
123 | # Visual Studio Trace Files
124 | *.e2e
125 |
126 | # TFS 2012 Local Workspace
127 | $tf/
128 |
129 | # Guidance Automation Toolkit
130 | *.gpState
131 |
132 | # ReSharper is a .NET coding add-in
133 | _ReSharper*/
134 | *.[Rr]e[Ss]harper
135 | *.DotSettings.user
136 |
137 | # TeamCity is a build add-in
138 | _TeamCity*
139 |
140 | # DotCover is a Code Coverage Tool
141 | *.dotCover
142 |
143 | # AxoCover is a Code Coverage Tool
144 | .axoCover/*
145 | !.axoCover/settings.json
146 |
147 | # Coverlet is a free, cross platform Code Coverage Tool
148 | coverage*.json
149 | coverage*.xml
150 | coverage*.info
151 |
152 | # Visual Studio code coverage results
153 | *.coverage
154 | *.coveragexml
155 |
156 | # NCrunch
157 | _NCrunch_*
158 | .*crunch*.local.xml
159 | nCrunchTemp_*
160 |
161 | # MightyMoose
162 | *.mm.*
163 | AutoTest.Net/
164 |
165 | # Web workbench (sass)
166 | .sass-cache/
167 |
168 | # Installshield output folder
169 | [Ee]xpress/
170 |
171 | # DocProject is a documentation generator add-in
172 | DocProject/buildhelp/
173 | DocProject/Help/*.HxT
174 | DocProject/Help/*.HxC
175 | DocProject/Help/*.hhc
176 | DocProject/Help/*.hhk
177 | DocProject/Help/*.hhp
178 | DocProject/Help/Html2
179 | DocProject/Help/html
180 |
181 | # Click-Once directory
182 | publish/
183 |
184 | # Publish Web Output
185 | *.[Pp]ublish.xml
186 | *.azurePubxml
187 | # Note: Comment the next line if you want to checkin your web deploy settings,
188 | # but database connection strings (with potential passwords) will be unencrypted
189 | *.pubxml
190 | *.publishproj
191 |
192 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
193 | # checkin your Azure Web App publish settings, but sensitive information contained
194 | # in these scripts will be unencrypted
195 | PublishScripts/
196 |
197 | # NuGet Packages
198 | *.nupkg
199 | # NuGet Symbol Packages
200 | *.snupkg
201 | # The packages folder can be ignored because of Package Restore
202 | **/[Pp]ackages/*
203 | # except build/, which is used as an MSBuild target.
204 | !**/[Pp]ackages/build/
205 | # Uncomment if necessary however generally it will be regenerated when needed
206 | #!**/[Pp]ackages/repositories.config
207 | # NuGet v3's project.json files produces more ignorable files
208 | *.nuget.props
209 | *.nuget.targets
210 |
211 | # Microsoft Azure Build Output
212 | csx/
213 | *.build.csdef
214 |
215 | # Microsoft Azure Emulator
216 | ecf/
217 | rcf/
218 |
219 | # Windows Store app package directories and files
220 | AppPackages/
221 | BundleArtifacts/
222 | Package.StoreAssociation.xml
223 | _pkginfo.txt
224 | *.appx
225 | *.appxbundle
226 | *.appxupload
227 |
228 | # Visual Studio cache files
229 | # files ending in .cache can be ignored
230 | *.[Cc]ache
231 | # but keep track of directories ending in .cache
232 | !?*.[Cc]ache/
233 |
234 | # Others
235 | ClientBin/
236 | ~$*
237 | *~
238 | *.dbmdl
239 | *.dbproj.schemaview
240 | *.jfm
241 | *.pfx
242 | *.publishsettings
243 | orleans.codegen.cs
244 |
245 | # Including strong name files can present a security risk
246 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
247 | #*.snk
248 |
249 | # Since there are multiple workflows, uncomment next line to ignore bower_components
250 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
251 | #bower_components/
252 |
253 | # RIA/Silverlight projects
254 | Generated_Code/
255 |
256 | # Backup & report files from converting an old project file
257 | # to a newer Visual Studio version. Backup files are not needed,
258 | # because we have git ;-)
259 | _UpgradeReport_Files/
260 | Backup*/
261 | UpgradeLog*.XML
262 | UpgradeLog*.htm
263 | ServiceFabricBackup/
264 | *.rptproj.bak
265 |
266 | # SQL Server files
267 | *.mdf
268 | *.ldf
269 | *.ndf
270 |
271 | # Business Intelligence projects
272 | *.rdl.data
273 | *.bim.layout
274 | *.bim_*.settings
275 | *.rptproj.rsuser
276 | *- [Bb]ackup.rdl
277 | *- [Bb]ackup ([0-9]).rdl
278 | *- [Bb]ackup ([0-9][0-9]).rdl
279 |
280 | # Microsoft Fakes
281 | FakesAssemblies/
282 |
283 | # GhostDoc plugin setting file
284 | *.GhostDoc.xml
285 |
286 | # Node.js Tools for Visual Studio
287 | .ntvs_analysis.dat
288 | node_modules/
289 |
290 | # Visual Studio 6 build log
291 | *.plg
292 |
293 | # Visual Studio 6 workspace options file
294 | *.opt
295 |
296 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
297 | *.vbw
298 |
299 | # Visual Studio LightSwitch build output
300 | **/*.HTMLClient/GeneratedArtifacts
301 | **/*.DesktopClient/GeneratedArtifacts
302 | **/*.DesktopClient/ModelManifest.xml
303 | **/*.Server/GeneratedArtifacts
304 | **/*.Server/ModelManifest.xml
305 | _Pvt_Extensions
306 |
307 | # Paket dependency manager
308 | .paket/paket.exe
309 | paket-files/
310 |
311 | # FAKE - F# Make
312 | .fake/
313 |
314 | # CodeRush personal settings
315 | .cr/personal
316 |
317 | # Python Tools for Visual Studio (PTVS)
318 | __pycache__/
319 | *.pyc
320 |
321 | # Cake - Uncomment if you are using it
322 | # tools/**
323 | # !tools/packages.config
324 |
325 | # Tabs Studio
326 | *.tss
327 |
328 | # Telerik's JustMock configuration file
329 | *.jmconfig
330 |
331 | # BizTalk build output
332 | *.btp.cs
333 | *.btm.cs
334 | *.odx.cs
335 | *.xsd.cs
336 |
337 | # OpenCover UI analysis results
338 | OpenCover/
339 |
340 | # Azure Stream Analytics local run output
341 | ASALocalRun/
342 |
343 | # MSBuild Binary and Structured Log
344 | *.binlog
345 |
346 | # NVidia Nsight GPU debugger configuration file
347 | *.nvuser
348 |
349 | # MFractors (Xamarin productivity tool) working folder
350 | .mfractor/
351 |
352 | # Local History for Visual Studio
353 | .localhistory/
354 |
355 | # BeatPulse healthcheck temp database
356 | healthchecksdb
357 |
358 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
359 | MigrationBackup/
360 |
361 | # Ionide (cross platform F# VS Code tools) working folder
362 | .ionide/
363 |
364 | # Fody - auto-generated XML schema
365 | FodyWeavers.xsd
366 |
367 | ##
368 | ## Visual studio for Mac
369 | ##
370 |
371 |
372 | # globs
373 | Makefile.in
374 | *.userprefs
375 | *.usertasks
376 | config.make
377 | config.status
378 | aclocal.m4
379 | install-sh
380 | autom4te.cache/
381 | *.tar.gz
382 | tarballs/
383 | test-results/
384 |
385 | # Mac bundle stuff
386 | *.dmg
387 | *.app
388 |
389 | # content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
390 | # General
391 | .DS_Store
392 | .AppleDouble
393 | .LSOverride
394 |
395 | # Icon must end with two \r
396 | Icon
397 |
398 |
399 | # Thumbnails
400 | ._*
401 |
402 | # Files that might appear in the root of a volume
403 | .DocumentRevisions-V100
404 | .fseventsd
405 | .Spotlight-V100
406 | .TemporaryItems
407 | .Trashes
408 | .VolumeIcon.icns
409 | .com.apple.timemachine.donotpresent
410 |
411 | # Directories potentially created on remote AFP share
412 | .AppleDB
413 | .AppleDesktop
414 | Network Trash Folder
415 | Temporary Items
416 | .apdisk
417 |
418 | # content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
419 | # Windows thumbnail cache files
420 | Thumbs.db
421 | ehthumbs.db
422 | ehthumbs_vista.db
423 |
424 | # Dump file
425 | *.stackdump
426 |
427 | # Folder config file
428 | [Dd]esktop.ini
429 |
430 | # Recycle Bin used on file shares
431 | $RECYCLE.BIN/
432 |
433 | # Windows Installer files
434 | *.cab
435 | *.msi
436 | *.msix
437 | *.msm
438 | *.msp
439 |
440 | # Windows shortcuts
441 | *.lnk
442 |
443 | # JetBrains Rider
444 | .idea/
445 | *.sln.iml
446 |
447 | ##
448 | ## Visual Studio Code
449 | ##
450 | .vscode/*
451 | !.vscode/settings.json
452 | !.vscode/tasks.json
453 | !.vscode/launch.json
454 | !.vscode/extensions.json
455 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.2.0",
3 | "configurations": [
4 | {
5 | // Use IntelliSense to find out which attributes exist for C# debugging
6 | // Use hover for the description of the existing attributes
7 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
8 | "name": ".NET Core Launch (web)",
9 | "type": "coreclr",
10 | "request": "launch",
11 | "preLaunchTask": "build",
12 | // If you have changed target frameworks, make sure to update the program path.
13 | "program": "${workspaceFolder}/bin/Debug/net6.0/MinimalApi.dll",
14 | "args": [],
15 | "cwd": "${workspaceFolder}",
16 | "stopAtEntry": false,
17 | // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
18 | "serverReadyAction": {
19 | "action": "openExternally",
20 | "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
21 | },
22 | "env": {
23 | "ASPNETCORE_ENVIRONMENT": "Development"
24 | },
25 | "sourceFileMap": {
26 | "/Views": "${workspaceFolder}/Views"
27 | }
28 | },
29 | {
30 | "name": ".NET Core Attach",
31 | "type": "coreclr",
32 | "request": "attach"
33 | }
34 | ]
35 | }
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "2.0.0",
3 | "tasks": [
4 | {
5 | "label": "build",
6 | "command": "dotnet",
7 | "type": "process",
8 | "args": [
9 | "build",
10 | "${workspaceFolder}/MinimalApi.csproj",
11 | "/property:GenerateFullPaths=true",
12 | "/consoleloggerparameters:NoSummary"
13 | ],
14 | "problemMatcher": "$msCompile"
15 | },
16 | {
17 | "label": "publish",
18 | "command": "dotnet",
19 | "type": "process",
20 | "args": [
21 | "publish",
22 | "${workspaceFolder}/MinimalApi.csproj",
23 | "/property:GenerateFullPaths=true",
24 | "/consoleloggerparameters:NoSummary"
25 | ],
26 | "problemMatcher": "$msCompile"
27 | },
28 | {
29 | "label": "watch",
30 | "command": "dotnet",
31 | "type": "process",
32 | "args": [
33 | "watch",
34 | "run",
35 | "${workspaceFolder}/MinimalApi.csproj",
36 | "/property:GenerateFullPaths=true",
37 | "/consoleloggerparameters:NoSummary"
38 | ],
39 | "problemMatcher": "$msCompile"
40 | }
41 | ]
42 | }
--------------------------------------------------------------------------------
/Data/Migrations/20211111034925_InitialMigrations.Designer.cs:
--------------------------------------------------------------------------------
1 | //
2 | using System;
3 | using Microsoft.EntityFrameworkCore;
4 | using Microsoft.EntityFrameworkCore.Infrastructure;
5 | using Microsoft.EntityFrameworkCore.Metadata;
6 | using Microsoft.EntityFrameworkCore.Migrations;
7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8 |
9 | #nullable disable
10 |
11 | namespace MinimalApi.Data.Migrations
12 | {
13 | [DbContext(typeof(TodoDbContext))]
14 | [Migration("20211111034925_InitialMigrations")]
15 | partial class InitialMigrations
16 | {
17 | protected override void BuildTargetModel(ModelBuilder modelBuilder)
18 | {
19 | #pragma warning disable 612, 618
20 | modelBuilder
21 | .HasAnnotation("ProductVersion", "6.0.0")
22 | .HasAnnotation("Relational:MaxIdentifierLength", 128);
23 |
24 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
25 |
26 | modelBuilder.Entity("TodoItem", b =>
27 | {
28 | b.Property("Id")
29 | .ValueGeneratedOnAdd()
30 | .HasColumnType("int");
31 |
32 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1);
33 |
34 | b.Property("IsCompleted")
35 | .HasColumnType("bit");
36 |
37 | b.Property("PeriodEnd")
38 | .ValueGeneratedOnAddOrUpdate()
39 | .HasColumnType("datetime2")
40 | .HasColumnName("PeriodEnd");
41 |
42 | b.Property("PeriodStart")
43 | .ValueGeneratedOnAddOrUpdate()
44 | .HasColumnType("datetime2")
45 | .HasColumnName("PeriodStart");
46 |
47 | b.Property("Title")
48 | .HasColumnType("nvarchar(max)");
49 |
50 | b.HasKey("Id");
51 |
52 | b.ToTable("TodoItems", (string)null);
53 |
54 | b.ToTable(tb => tb.IsTemporal(ttb =>
55 | {
56 | ttb
57 | .HasPeriodStart("PeriodStart")
58 | .HasColumnName("PeriodStart");
59 | ttb
60 | .HasPeriodEnd("PeriodEnd")
61 | .HasColumnName("PeriodEnd");
62 | }
63 | ));
64 | });
65 | #pragma warning restore 612, 618
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/Data/Migrations/20211111034925_InitialMigrations.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.EntityFrameworkCore.Migrations;
3 |
4 | #nullable disable
5 |
6 | namespace MinimalApi.Data.Migrations
7 | {
8 | public partial class InitialMigrations : Migration
9 | {
10 | protected override void Up(MigrationBuilder migrationBuilder)
11 | {
12 | migrationBuilder.CreateTable(
13 | name: "TodoItems",
14 | columns: table => new
15 | {
16 | Id = table.Column(type: "int", nullable: false)
17 | .Annotation("SqlServer:Identity", "1, 1"),
18 | Title = table.Column(type: "nvarchar(max)", nullable: true),
19 | IsCompleted = table.Column(type: "bit", nullable: false),
20 | PeriodEnd = table.Column(type: "datetime2", nullable: false)
21 | .Annotation("SqlServer:IsTemporal", true)
22 | .Annotation("SqlServer:TemporalPeriodEndColumnName", "PeriodEnd")
23 | .Annotation("SqlServer:TemporalPeriodStartColumnName", "PeriodStart"),
24 | PeriodStart = table.Column(type: "datetime2", nullable: false)
25 | .Annotation("SqlServer:IsTemporal", true)
26 | .Annotation("SqlServer:TemporalPeriodEndColumnName", "PeriodEnd")
27 | .Annotation("SqlServer:TemporalPeriodStartColumnName", "PeriodStart")
28 | },
29 | constraints: table =>
30 | {
31 | table.PrimaryKey("PK_TodoItems", x => x.Id);
32 | })
33 | .Annotation("SqlServer:IsTemporal", true)
34 | .Annotation("SqlServer:TemporalHistoryTableName", "TodoItemsHistory")
35 | .Annotation("SqlServer:TemporalHistoryTableSchema", null)
36 | .Annotation("SqlServer:TemporalPeriodEndColumnName", "PeriodEnd")
37 | .Annotation("SqlServer:TemporalPeriodStartColumnName", "PeriodStart");
38 | }
39 |
40 | protected override void Down(MigrationBuilder migrationBuilder)
41 | {
42 | migrationBuilder.DropTable(
43 | name: "TodoItems")
44 | .Annotation("SqlServer:IsTemporal", true)
45 | .Annotation("SqlServer:TemporalHistoryTableName", "TodoItemsHistory")
46 | .Annotation("SqlServer:TemporalHistoryTableSchema", null)
47 | .Annotation("SqlServer:TemporalPeriodEndColumnName", "PeriodEnd")
48 | .Annotation("SqlServer:TemporalPeriodStartColumnName", "PeriodStart");
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Data/Migrations/TodoDbContextModelSnapshot.cs:
--------------------------------------------------------------------------------
1 | //
2 | using System;
3 | using Microsoft.EntityFrameworkCore;
4 | using Microsoft.EntityFrameworkCore.Infrastructure;
5 | using Microsoft.EntityFrameworkCore.Metadata;
6 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
7 |
8 | #nullable disable
9 |
10 | namespace MinimalApi.Data.Migrations
11 | {
12 | [DbContext(typeof(TodoDbContext))]
13 | partial class TodoDbContextModelSnapshot : ModelSnapshot
14 | {
15 | protected override void BuildModel(ModelBuilder modelBuilder)
16 | {
17 | #pragma warning disable 612, 618
18 | modelBuilder
19 | .HasAnnotation("ProductVersion", "6.0.0")
20 | .HasAnnotation("Relational:MaxIdentifierLength", 128);
21 |
22 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
23 |
24 | modelBuilder.Entity("TodoItem", b =>
25 | {
26 | b.Property("Id")
27 | .ValueGeneratedOnAdd()
28 | .HasColumnType("int");
29 |
30 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1);
31 |
32 | b.Property("IsCompleted")
33 | .HasColumnType("bit");
34 |
35 | b.Property("PeriodEnd")
36 | .ValueGeneratedOnAddOrUpdate()
37 | .HasColumnType("datetime2")
38 | .HasColumnName("PeriodEnd");
39 |
40 | b.Property("PeriodStart")
41 | .ValueGeneratedOnAddOrUpdate()
42 | .HasColumnType("datetime2")
43 | .HasColumnName("PeriodStart");
44 |
45 | b.Property("Title")
46 | .HasColumnType("nvarchar(max)");
47 |
48 | b.HasKey("Id");
49 |
50 | b.ToTable("TodoItems", (string)null);
51 |
52 | b.ToTable(tb => tb.IsTemporal(ttb =>
53 | {
54 | ttb
55 | .HasPeriodStart("PeriodStart")
56 | .HasColumnName("PeriodStart");
57 | ttb
58 | .HasPeriodEnd("PeriodEnd")
59 | .HasColumnName("PeriodEnd");
60 | }
61 | ));
62 | });
63 | #pragma warning restore 612, 618
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/MinimalApi.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 | enable
6 |
7 |
8 |
9 |
10 |
11 | runtime; build; native; contentfiles; analyzers; buildtransitive
12 | all
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/MinimalApi.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30114.105
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MinimalApi", "MinimalApi.csproj", "{30423E76-9C09-4CB3-A442-BC107463E885}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(SolutionProperties) = preSolution
14 | HideSolutionNode = FALSE
15 | EndGlobalSection
16 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
17 | {30423E76-9C09-4CB3-A442-BC107463E885}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18 | {30423E76-9C09-4CB3-A442-BC107463E885}.Debug|Any CPU.Build.0 = Debug|Any CPU
19 | {30423E76-9C09-4CB3-A442-BC107463E885}.Release|Any CPU.ActiveCfg = Release|Any CPU
20 | {30423E76-9C09-4CB3-A442-BC107463E885}.Release|Any CPU.Build.0 = Release|Any CPU
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/Program.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Builder;
2 | using Microsoft.AspNetCore.Http;
3 | using Microsoft.EntityFrameworkCore;
4 | using Microsoft.Extensions.Configuration;
5 | using Microsoft.Extensions.DependencyInjection;
6 | using Microsoft.Extensions.Diagnostics.HealthChecks;
7 | using Microsoft.Extensions.Hosting;
8 | using Microsoft.OpenApi.Models;
9 |
10 | using System;
11 | using System.ComponentModel.DataAnnotations;
12 | using System.Linq;
13 |
14 | var builder = WebApplication.CreateBuilder(args);
15 | builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
16 | builder.Services.AddEndpointsApiExplorer();
17 | builder.Services.AddSwaggerGen(setup => setup.SwaggerDoc("v1", new OpenApiInfo()
18 | {
19 | Description = "Todo web api implementation using Minimal Api in Asp.Net Core",
20 | Title = "Todo Api",
21 | Version = "v1",
22 | Contact = new OpenApiContact()
23 | {
24 | Name = "anuraj",
25 | Url = new Uri("https://dotnetthoughts.net")
26 | }
27 | }));
28 |
29 | builder.Services.AddDatabaseDeveloperPageExceptionFilter();
30 | builder.Services.AddHealthChecks().AddDbContextCheck();
31 | var app = builder.Build();
32 |
33 | if (app.Environment.IsDevelopment())
34 | {
35 | app.UseDeveloperExceptionPage();
36 | }
37 |
38 | app.UseSwagger();
39 |
40 | app.MapGet("/todoitems", async (TodoDbContext dbContext) => await dbContext.TodoItems.ToListAsync()).WithTags(new[] { "Read", "CRUD" });
41 |
42 | app.MapGet("/todoitems/{id}", async (TodoDbContext dbContext, int id) =>
43 | await dbContext.TodoItems.FindAsync(id) is TodoItem todo ? Results.Ok(todo) : Results.NotFound()).WithTags(new[] { "Read", "ReadOne", "CRUD" });
44 |
45 | app.MapPost("/todoitems", async (TodoDbContext dbContext, TodoItem todoItem) =>
46 | {
47 | dbContext.TodoItems.Add(todoItem);
48 | await dbContext.SaveChangesAsync();
49 | return Results.Created($"/todoitems/{todoItem.Id}", todoItem);
50 | }).WithTags(new[] { "Create", "CRUD" }).Accepts("application/json").Produces(201, typeof(TodoItem));
51 |
52 | app.MapPut("/todoitems/{id}", async (TodoDbContext dbContext, int id, TodoItem inputTodoItem) =>
53 | {
54 | if (await dbContext.TodoItems.FindAsync(id) is TodoItem todoItem)
55 | {
56 | todoItem.IsCompleted = inputTodoItem.IsCompleted;
57 | await dbContext.SaveChangesAsync();
58 | return Results.NoContent();
59 | }
60 |
61 | return Results.NotFound();
62 | }).WithTags(new[] { "Update", "CRUD" }).Accepts("application/json").Produces(201, typeof(TodoItem)).ProducesProblem(404);
63 |
64 | app.MapDelete("/todoitems/{id}", async (TodoDbContext dbContext, int id) =>
65 | {
66 | if (await dbContext.TodoItems.FindAsync(id) is TodoItem todoItem)
67 | {
68 | dbContext.TodoItems.Remove(todoItem);
69 | await dbContext.SaveChangesAsync();
70 | return Results.NoContent();
71 | }
72 |
73 | return Results.NotFound();
74 | }).WithTags(new[] { "Delete", "CRUD" }).Accepts("application/json").Produces(201, typeof(TodoItem)).ProducesProblem(404);
75 |
76 | app.MapGet("/health", async (HealthCheckService healthCheckService) =>
77 | {
78 | var report = await healthCheckService.CheckHealthAsync();
79 | return report.Status == HealthStatus.Healthy ? Results.Ok(report) : Results.StatusCode(StatusCodes.Status503ServiceUnavailable);
80 | }).WithTags(new[] { "Health" }).Produces(200).ProducesProblem(503);
81 |
82 | app.MapGet("/todoitems/history", async (TodoDbContext dbContext) => await dbContext.TodoItems
83 | .TemporalAll()
84 | .OrderBy(todoItem => EF.Property(todoItem, "PeriodStart"))
85 | .Select(todoItem => new TodoItemAudit
86 | {
87 | Title = todoItem.Title,
88 | IsCompleted = todoItem.IsCompleted,
89 | PeriodStart = EF.Property(todoItem, "PeriodStart"),
90 | PeriodEnd = EF.Property(todoItem, "PeriodEnd")
91 | })
92 | .ToListAsync()).WithTags(new[] { "EF Core Feature" });
93 |
94 | app.UseSwaggerUI(c =>
95 | {
96 | c.SwaggerEndpoint("/swagger/v1/swagger.json", "Todo Api v1");
97 | c.RoutePrefix = string.Empty;
98 | });
99 | app.Run();
100 |
101 | public class TodoDbContext : DbContext
102 | {
103 | public TodoDbContext(DbContextOptions options)
104 | : base(options) { }
105 |
106 | protected override void OnModelCreating(ModelBuilder modelBuilder)
107 | {
108 | modelBuilder.Entity().ToTable("TodoItems", t => t.IsTemporal());
109 | }
110 |
111 | public DbSet TodoItems => Set();
112 | }
113 |
114 | public class TodoItem
115 | {
116 | public int Id { get; set; }
117 | [Required]
118 | public string? Title { get; set; }
119 | public bool IsCompleted { get; set; }
120 | }
121 |
122 | public class TodoItemAudit
123 | {
124 | public string? Title { get; set; }
125 | public bool IsCompleted { get; set; }
126 | public DateTime PeriodStart { get; set; }
127 | public DateTime PeriodEnd { get; set; }
128 | }
--------------------------------------------------------------------------------
/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://json.schemastore.org/launchsettings.json",
3 | "iisSettings": {
4 | "windowsAuthentication": false,
5 | "anonymousAuthentication": true,
6 | "iisExpress": {
7 | "applicationUrl": "http://localhost:21244",
8 | "sslPort": 44373
9 | }
10 | },
11 | "profiles": {
12 | "MinimalApi": {
13 | "commandName": "Project",
14 | "dotnetRunMessages": true,
15 | "launchBrowser": true,
16 | "launchUrl": "swagger",
17 | "applicationUrl": "https://localhost:5001;http://localhost:5000",
18 | "environmentVariables": {
19 | "ASPNETCORE_ENVIRONMENT": "Development"
20 | }
21 | },
22 | "IIS Express": {
23 | "commandName": "IISExpress",
24 | "launchBrowser": true,
25 | "launchUrl": "swagger",
26 | "environmentVariables": {
27 | "ASPNETCORE_ENVIRONMENT": "Development"
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ASP.NET Core 6.0 - Minimal API Example.
2 |
3 | Todo API implementation using Minimal API, Entity Framework Core SQL Server Provider and Open API.
4 |
5 | ## Features
6 |
7 | * CRUD operations using Minimal API .NET 6.0 and Sql Server
8 | * Health Checks implementation for Minimal APIs
9 | * Open API - Support for Tags
10 | * EF Core new features
11 | - Temporal Tables in Sql Server
12 | - Run migration using EF Bundles
--------------------------------------------------------------------------------
/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | },
9 | "AllowedHosts": "*",
10 | "ConnectionStrings": {
11 | "DefaultConnection": "Server=SOCLAP01;Initial Catalog=TodoDatabase;Persist Security Info=False;User ID=sa;Password=Socxo@123;"
12 | }
13 | }
14 |
--------------------------------------------------------------------------------