├── .gitignore ├── .vscode ├── launch.json ├── settings.json └── tasks.json ├── ContosoOnline ├── ContosoOnline.AppHost │ ├── ContosoOnline.AppHost.csproj │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── appsettings.Development.json │ ├── appsettings.json │ └── aspire-manifest.json ├── ContosoOnline.ServiceDefaults │ ├── ContosoOnline.ServiceDefaults.csproj │ └── Extensions.cs ├── ContosoOnline.sln ├── OrderProcessor │ ├── OrderProcessingRequest.cs │ ├── OrderProcessingWorker.cs │ ├── OrderProcessor.csproj │ ├── OrderServiceClient.cs │ ├── ProductServiceClient.cs │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── Protos │ │ └── products.proto │ ├── appsettings.Development.json │ └── appsettings.json ├── Orders │ ├── DatabaseInitializer.cs │ ├── Migrations │ │ ├── 20240120074020_initial_create.Designer.cs │ │ ├── 20240120074020_initial_create.cs │ │ └── OrdersDbContextModelSnapshot.cs │ ├── Models.cs │ ├── Orders.csproj │ ├── OrdersApi.cs │ ├── OrdersDbContext.cs │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ └── appsettings.json ├── Products │ ├── ProductServices.cs │ ├── Products.csproj │ ├── ProductsGrpcService.cs │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── Protos │ │ └── products.proto │ └── appsettings.json └── Store │ ├── App.razor │ ├── Pages │ ├── Error.cshtml │ ├── Error.cshtml.cs │ ├── Index.razor │ └── _Host.cshtml │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Protos │ └── products.proto │ ├── Services │ └── OrderServiceClient.cs │ ├── Shared │ ├── MainLayout.razor │ ├── MainLayout.razor.css │ ├── NavMenu.razor │ └── NavMenu.razor.css │ ├── Store.csproj │ ├── _Imports.razor │ ├── appsettings.Development.json │ ├── appsettings.json │ └── wwwroot │ ├── css │ ├── bootstrap │ │ ├── bootstrap.min.css │ │ └── bootstrap.min.css.map │ ├── open-iconic │ │ ├── FONT-LICENSE │ │ ├── ICON-LICENSE │ │ ├── README.md │ │ └── font │ │ │ ├── css │ │ │ └── open-iconic-bootstrap.min.css │ │ │ └── fonts │ │ │ ├── open-iconic.eot │ │ │ ├── open-iconic.otf │ │ │ ├── open-iconic.svg │ │ │ ├── open-iconic.ttf │ │ │ └── open-iconic.woff │ └── site.css │ └── favicon.png ├── LICENSE ├── README.md ├── azure.yaml └── docs ├── azd-install-script.md ├── azd-installation-writeup.md ├── env-setup-guide.md ├── topology.png └── topology.svg /.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/main/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 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 298 | *.vbp 299 | 300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 301 | *.dsw 302 | *.dsp 303 | 304 | # Visual Studio 6 technical files 305 | *.ncb 306 | *.aps 307 | 308 | # Visual Studio LightSwitch build output 309 | **/*.HTMLClient/GeneratedArtifacts 310 | **/*.DesktopClient/GeneratedArtifacts 311 | **/*.DesktopClient/ModelManifest.xml 312 | **/*.Server/GeneratedArtifacts 313 | **/*.Server/ModelManifest.xml 314 | _Pvt_Extensions 315 | 316 | # Paket dependency manager 317 | .paket/paket.exe 318 | paket-files/ 319 | 320 | # FAKE - F# Make 321 | .fake/ 322 | 323 | # CodeRush personal settings 324 | .cr/personal 325 | 326 | # Python Tools for Visual Studio (PTVS) 327 | __pycache__/ 328 | *.pyc 329 | 330 | # Cake - Uncomment if you are using it 331 | # tools/** 332 | # !tools/packages.config 333 | 334 | # Tabs Studio 335 | *.tss 336 | 337 | # Telerik's JustMock configuration file 338 | *.jmconfig 339 | 340 | # BizTalk build output 341 | *.btp.cs 342 | *.btm.cs 343 | *.odx.cs 344 | *.xsd.cs 345 | 346 | # OpenCover UI analysis results 347 | OpenCover/ 348 | 349 | # Azure Stream Analytics local run output 350 | ASALocalRun/ 351 | 352 | # MSBuild Binary and Structured Log 353 | *.binlog 354 | 355 | # NVidia Nsight GPU debugger configuration file 356 | *.nvuser 357 | 358 | # MFractors (Xamarin productivity tool) working folder 359 | .mfractor/ 360 | 361 | # Local History for Visual Studio 362 | .localhistory/ 363 | 364 | # Visual Studio History (VSHistory) files 365 | .vshistory/ 366 | 367 | # BeatPulse healthcheck temp database 368 | healthchecksdb 369 | 370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 371 | MigrationBackup/ 372 | 373 | # Ionide (cross platform F# VS Code tools) working folder 374 | .ionide/ 375 | 376 | # Fody - auto-generated XML schema 377 | FodyWeavers.xsd 378 | 379 | # VS Code files for those working on multiple tools 380 | .vscode/* 381 | !.vscode/settings.json 382 | !.vscode/tasks.json 383 | !.vscode/launch.json 384 | !.vscode/extensions.json 385 | *.code-workspace 386 | 387 | # Local History for Visual Studio Code 388 | .history/ 389 | 390 | # Windows Installer files from build outputs 391 | *.cab 392 | *.msi 393 | *.msix 394 | *.msm 395 | *.msp 396 | 397 | # JetBrains Rider 398 | *.sln.iml 399 | .azure 400 | -------------------------------------------------------------------------------- /.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/dotnet/vscode-csharp/blob/main/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}/ContosoOnline/Store/bin/Debug/net8.0/Store.dll", 14 | "args": [], 15 | "cwd": "${workspaceFolder}/ContosoOnline/Store", 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/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "dotnet.defaultSolution": "ContosoOnline/ContosoOnline.sln" 3 | } -------------------------------------------------------------------------------- /.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}/ContosoOnline/ContosoOnline.sln", 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}/ContosoOnline/ContosoOnline.sln", 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 | "--project", 36 | "${workspaceFolder}/ContosoOnline/ContosoOnline.sln" 37 | ], 38 | "problemMatcher": "$msCompile" 39 | } 40 | ] 41 | } -------------------------------------------------------------------------------- /ContosoOnline/ContosoOnline.AppHost/ContosoOnline.AppHost.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | true 9 | True 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /ContosoOnline/ContosoOnline.AppHost/Program.cs: -------------------------------------------------------------------------------- 1 | var builder = DistributedApplication.CreateBuilder(args); 2 | 3 | var ordersDb = builder.AddPostgres("postgres").AddDatabase("ordersdb"); 4 | 5 | var products = builder.AddProject("products"); 6 | 7 | var ordersApi = builder.AddProject("orders") 8 | .WithReference(ordersDb); 9 | 10 | builder.AddProject("store") 11 | .WithReference(products) 12 | .WithReference(ordersApi); 13 | 14 | builder.AddProject("orderprocessor") 15 | .WithReference(ordersApi) 16 | .WithReference(products); 17 | 18 | builder.Build().Run(); 19 | -------------------------------------------------------------------------------- /ContosoOnline/ContosoOnline.AppHost/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "profiles": { 4 | "http": { 5 | "commandName": "Project", 6 | "dotnetRunMessages": true, 7 | "launchBrowser": true, 8 | "applicationUrl": "http://localhost:15070", 9 | "environmentVariables": { 10 | "ASPNETCORE_ENVIRONMENT": "Development", 11 | "DOTNET_ENVIRONMENT": "Development", 12 | "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16155" 13 | } 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ContosoOnline/ContosoOnline.AppHost/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ContosoOnline/ContosoOnline.AppHost/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning", 6 | "Aspire.Hosting.Dcp": "Warning" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /ContosoOnline/ContosoOnline.AppHost/aspire-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "resources": { 3 | "ordersdb": { 4 | "type": "postgres.server.v0" 5 | }, 6 | "products": { 7 | "type": "project.v0", 8 | "path": "../Products/Products.csproj", 9 | "env": { 10 | "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true", 11 | "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true" 12 | }, 13 | "bindings": { 14 | "http": { 15 | "scheme": "http", 16 | "protocol": "tcp", 17 | "transport": "http2" 18 | }, 19 | "https": { 20 | "scheme": "https", 21 | "protocol": "tcp", 22 | "transport": "http2" 23 | } 24 | } 25 | }, 26 | "orders": { 27 | "type": "project.v0", 28 | "path": "../Orders/Orders.csproj", 29 | "env": { 30 | "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true", 31 | "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true", 32 | "ConnectionStrings__ordersdb": "{ordersdb.connectionString}" 33 | }, 34 | "bindings": { 35 | "http": { 36 | "scheme": "http", 37 | "protocol": "tcp", 38 | "transport": "http" 39 | }, 40 | "https": { 41 | "scheme": "https", 42 | "protocol": "tcp", 43 | "transport": "http" 44 | } 45 | } 46 | }, 47 | "store": { 48 | "type": "project.v0", 49 | "path": "../Store/Store.csproj", 50 | "env": { 51 | "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true", 52 | "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true", 53 | "services__products__0": "{products.bindings.http.url}", 54 | "services__products__1": "{products.bindings.https.url}", 55 | "services__orders__0": "{orders.bindings.http.url}", 56 | "services__orders__1": "{orders.bindings.https.url}" 57 | }, 58 | "bindings": { 59 | "http": { 60 | "scheme": "http", 61 | "protocol": "tcp", 62 | "transport": "http" 63 | }, 64 | "https": { 65 | "scheme": "https", 66 | "protocol": "tcp", 67 | "transport": "http" 68 | } 69 | } 70 | }, 71 | "orderprocessor": { 72 | "type": "project.v0", 73 | "path": "../OrderProcessor/OrderProcessor.csproj", 74 | "env": { 75 | "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true", 76 | "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true", 77 | "services__orders__0": "{orders.bindings.http.url}", 78 | "services__orders__1": "{orders.bindings.https.url}", 79 | "services__products__0": "{products.bindings.http.url}", 80 | "services__products__1": "{products.bindings.https.url}" 81 | } 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /ContosoOnline/ContosoOnline.ServiceDefaults/ContosoOnline.ServiceDefaults.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Library 5 | net8.0 6 | enable 7 | enable 8 | true 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /ContosoOnline/ContosoOnline.ServiceDefaults/Extensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using Microsoft.AspNetCore.Diagnostics.HealthChecks; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using Microsoft.Extensions.Diagnostics.HealthChecks; 5 | using Microsoft.Extensions.Logging; 6 | using OpenTelemetry.Logs; 7 | using OpenTelemetry.Metrics; 8 | using OpenTelemetry.Trace; 9 | 10 | namespace Microsoft.Extensions.Hosting; 11 | 12 | public static class Extensions 13 | { 14 | public static IHostApplicationBuilder AddServiceDefaults(this IHostApplicationBuilder builder) 15 | { 16 | builder.ConfigureOpenTelemetry(); 17 | 18 | builder.AddDefaultHealthChecks(); 19 | 20 | builder.Services.AddServiceDiscovery(); 21 | 22 | builder.Services.ConfigureHttpClientDefaults(http => 23 | { 24 | // Turn on resilience by default 25 | // http.AddStandardResilienceHandler(); 26 | 27 | // Turn on service discovery by default 28 | http.UseServiceDiscovery(); 29 | }); 30 | 31 | return builder; 32 | } 33 | 34 | public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicationBuilder builder) 35 | { 36 | builder.Logging.AddOpenTelemetry(logging => 37 | { 38 | logging.IncludeFormattedMessage = true; 39 | logging.IncludeScopes = true; 40 | }); 41 | 42 | builder.Services.AddOpenTelemetry() 43 | .WithMetrics(metrics => 44 | { 45 | metrics.AddRuntimeInstrumentation() 46 | .AddBuiltInMeters(); 47 | }) 48 | .WithTracing(tracing => 49 | { 50 | if (builder.Environment.IsDevelopment()) 51 | { 52 | // We want to view all traces in development 53 | tracing.SetSampler(new AlwaysOnSampler()); 54 | } 55 | 56 | tracing.AddAspNetCoreInstrumentation() 57 | .AddGrpcClientInstrumentation() 58 | .AddHttpClientInstrumentation(); 59 | }); 60 | 61 | builder.AddOpenTelemetryExporters(); 62 | 63 | return builder; 64 | } 65 | 66 | private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostApplicationBuilder builder) 67 | { 68 | var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]); 69 | 70 | if (useOtlpExporter) 71 | { 72 | builder.Services.Configure(logging => logging.AddOtlpExporter()); 73 | builder.Services.ConfigureOpenTelemetryMeterProvider(metrics => metrics.AddOtlpExporter()); 74 | builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddOtlpExporter()); 75 | } 76 | 77 | // Uncomment the following lines to enable the Prometheus exporter (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package) 78 | // builder.Services.AddOpenTelemetry() 79 | // .WithMetrics(metrics => metrics.AddPrometheusExporter()); 80 | 81 | // Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.Exporter package) 82 | // builder.Services.AddOpenTelemetry() 83 | // .UseAzureMonitor(); 84 | 85 | return builder; 86 | } 87 | 88 | public static IHostApplicationBuilder AddDefaultHealthChecks(this IHostApplicationBuilder builder) 89 | { 90 | builder.Services.AddHealthChecks() 91 | // Add a default liveness check to ensure app is responsive 92 | .AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]); 93 | 94 | return builder; 95 | } 96 | 97 | public static WebApplication MapDefaultEndpoints(this WebApplication app) 98 | { 99 | // Uncomment the following line to enable the Prometheus endpoint (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package) 100 | // app.MapPrometheusScrapingEndpoint(); 101 | 102 | // All health checks must pass for app to be considered ready to accept traffic after starting 103 | app.MapHealthChecks("/health"); 104 | 105 | // Only health checks tagged with the "live" tag must pass for app to be considered alive 106 | app.MapHealthChecks("/alive", new HealthCheckOptions 107 | { 108 | Predicate = r => r.Tags.Contains("live") 109 | }); 110 | 111 | return app; 112 | } 113 | 114 | private static MeterProviderBuilder AddBuiltInMeters(this MeterProviderBuilder meterProviderBuilder) => 115 | meterProviderBuilder.AddMeter( 116 | "Microsoft.AspNetCore.Hosting", 117 | "Microsoft.AspNetCore.Server.Kestrel", 118 | "System.Net.Http"); 119 | } 120 | -------------------------------------------------------------------------------- /ContosoOnline/ContosoOnline.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.6.33626.354 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Orders", "Orders\Orders.csproj", "{707DD638-D2BD-4EB9-AE3D-4FFBB846D294}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Products", "Products\Products.csproj", "{6E7A43D5-5F93-49C3-A89F-31644350F18A}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrderProcessor", "OrderProcessor\OrderProcessor.csproj", "{F51C5A7B-3832-4BE3-9636-D5156E47E40C}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Store", "Store\Store.csproj", "{0BDF7868-40E2-47FE-BD35-D661E069CAAD}" 13 | EndProject 14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ContosoOnline.AppHost", "ContosoOnline.AppHost\ContosoOnline.AppHost.csproj", "{BA2FFA24-D295-43AF-B1A5-383885411F9A}" 15 | EndProject 16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ContosoOnline.ServiceDefaults", "ContosoOnline.ServiceDefaults\ContosoOnline.ServiceDefaults.csproj", "{CB2DB17A-8F7F-49AF-BCBE-92036E3A8499}" 17 | EndProject 18 | Global 19 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 20 | Debug|Any CPU = Debug|Any CPU 21 | Release|Any CPU = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 24 | {707DD638-D2BD-4EB9-AE3D-4FFBB846D294}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {707DD638-D2BD-4EB9-AE3D-4FFBB846D294}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {707DD638-D2BD-4EB9-AE3D-4FFBB846D294}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {707DD638-D2BD-4EB9-AE3D-4FFBB846D294}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {6E7A43D5-5F93-49C3-A89F-31644350F18A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {6E7A43D5-5F93-49C3-A89F-31644350F18A}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {6E7A43D5-5F93-49C3-A89F-31644350F18A}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {6E7A43D5-5F93-49C3-A89F-31644350F18A}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {F51C5A7B-3832-4BE3-9636-D5156E47E40C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {F51C5A7B-3832-4BE3-9636-D5156E47E40C}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {F51C5A7B-3832-4BE3-9636-D5156E47E40C}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {F51C5A7B-3832-4BE3-9636-D5156E47E40C}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {0BDF7868-40E2-47FE-BD35-D661E069CAAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 37 | {0BDF7868-40E2-47FE-BD35-D661E069CAAD}.Debug|Any CPU.Build.0 = Debug|Any CPU 38 | {0BDF7868-40E2-47FE-BD35-D661E069CAAD}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {0BDF7868-40E2-47FE-BD35-D661E069CAAD}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {BA2FFA24-D295-43AF-B1A5-383885411F9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 41 | {BA2FFA24-D295-43AF-B1A5-383885411F9A}.Debug|Any CPU.Build.0 = Debug|Any CPU 42 | {BA2FFA24-D295-43AF-B1A5-383885411F9A}.Release|Any CPU.ActiveCfg = Release|Any CPU 43 | {BA2FFA24-D295-43AF-B1A5-383885411F9A}.Release|Any CPU.Build.0 = Release|Any CPU 44 | {CB2DB17A-8F7F-49AF-BCBE-92036E3A8499}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 45 | {CB2DB17A-8F7F-49AF-BCBE-92036E3A8499}.Debug|Any CPU.Build.0 = Debug|Any CPU 46 | {CB2DB17A-8F7F-49AF-BCBE-92036E3A8499}.Release|Any CPU.ActiveCfg = Release|Any CPU 47 | {CB2DB17A-8F7F-49AF-BCBE-92036E3A8499}.Release|Any CPU.Build.0 = Release|Any CPU 48 | EndGlobalSection 49 | GlobalSection(SolutionProperties) = preSolution 50 | HideSolutionNode = FALSE 51 | EndGlobalSection 52 | GlobalSection(ExtensibilityGlobals) = postSolution 53 | SolutionGuid = {00341F0A-ED8F-45E5-A02B-8573A011F0E5} 54 | EndGlobalSection 55 | EndGlobal 56 | -------------------------------------------------------------------------------- /ContosoOnline/OrderProcessor/OrderProcessingRequest.cs: -------------------------------------------------------------------------------- 1 | public class OrderProcessingRequest(ILogger logger, 2 | OrderServiceClient ordersClient, 3 | ProductServiceClient productsClient) 4 | { 5 | public async Task ProcessOrdersAsync(CancellationToken stoppingToken) 6 | { 7 | var orders = await ordersClient.GetOrdersAsync(stoppingToken); 8 | 9 | // REVIEW: Should we do this concurrently? 10 | foreach (var order in orders) 11 | { 12 | if (stoppingToken.IsCancellationRequested) 13 | { 14 | break; 15 | } 16 | 17 | try 18 | { 19 | await ProcessOrderAsync(order); 20 | } 21 | catch (Exception ex) 22 | { 23 | logger.LogError(ex, "Error processing order {OrderId}", order.OrderId); 24 | } 25 | } 26 | } 27 | 28 | private async Task ProcessOrderAsync(Order order) 29 | { 30 | logger.LogInformation("Checking inventory for Order {OrderId}", order.OrderId); 31 | 32 | bool canWeFulfillOrder = true; 33 | var itemTasks = new List(); 34 | 35 | foreach (var cartItem in order.Cart) 36 | { 37 | itemTasks.Add(Task.Run(async () => 38 | { 39 | logger.LogInformation("Checking inventory for product id {ProductId} in order {OrderId}", cartItem.ProductId, order.OrderId); 40 | 41 | var inStock = await productsClient.CanInventoryFulfill(cartItem.ProductId, cartItem.Quantity); 42 | 43 | if (inStock) 44 | { 45 | logger.LogInformation("Inventory OK for product id {ProductId} in order {OrderId}", cartItem.ProductId, order.OrderId); 46 | } 47 | else 48 | { 49 | logger.LogInformation("Not enough inventory for product id {ProductId} in order {OrderId}", cartItem.ProductId, order.OrderId); 50 | 51 | canWeFulfillOrder = canWeFulfillOrder && inStock; 52 | } 53 | })); 54 | } 55 | 56 | await Task.WhenAll(itemTasks); 57 | 58 | if (canWeFulfillOrder) 59 | { 60 | var invTasks = new List(); 61 | 62 | foreach (var cartItem in order.Cart) 63 | { 64 | invTasks.Add(Task.Run(async () => 65 | { 66 | logger.LogInformation("Removing {Quantity} of product id {ProductId} from inventory", cartItem.Quantity, cartItem.ProductId); 67 | 68 | await productsClient.SubtractInventory(cartItem.ProductId, cartItem.Quantity); 69 | 70 | logger.LogInformation("Removed {Quantity} of product id {ProductId} from inventory", cartItem.Quantity, cartItem.ProductId); 71 | })); 72 | } 73 | 74 | logger.LogInformation("Marking order {OrderId} as ready for shipment", order.OrderId); 75 | 76 | invTasks.Add(ordersClient.MarkOrderReadyForShipment(order)); 77 | 78 | logger.LogInformation("Marked order {OrderId} as ready for shipment", order.OrderId); 79 | 80 | await Task.WhenAll(invTasks); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /ContosoOnline/OrderProcessor/OrderProcessingWorker.cs: -------------------------------------------------------------------------------- 1 | public class OrderProcessingWorker(ILogger logger, 2 | IServiceScopeFactory serviceScopeFactory, 3 | IConfiguration configuration) 4 | : BackgroundService 5 | { 6 | private TimeSpan CheckOrderInterval => TimeSpan.FromSeconds(5); 7 | 8 | protected override async Task ExecuteAsync(CancellationToken stoppingToken) 9 | { 10 | while (!stoppingToken.IsCancellationRequested) 11 | { 12 | logger.LogInformation($"Worker running at: {DateTime.UtcNow}"); 13 | 14 | await using var scope = serviceScopeFactory.CreateAsyncScope(); 15 | 16 | var request = scope.ServiceProvider.GetRequiredService(); 17 | 18 | try 19 | { 20 | await request.ProcessOrdersAsync(stoppingToken); 21 | } 22 | catch (OperationCanceledException) 23 | { 24 | // We're shutting down 25 | break; 26 | } 27 | catch (Exception ex) 28 | { 29 | logger.LogError(ex, "Error getting orders"); 30 | } 31 | 32 | await Task.Delay(CheckOrderInterval, stoppingToken); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ContosoOnline/OrderProcessor/OrderProcessor.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | true 8 | Linux 9 | True 10 | preview 11 | ad065b74-0b55-4bb5-9321-225a9bf3ae30 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | 25 | 26 | 28 | 30 | 31 | 32 | 33 | 34 | 36 | 37 | 38 | 39 | 40 | Client 41 | 42 | 43 | -------------------------------------------------------------------------------- /ContosoOnline/OrderProcessor/OrderServiceClient.cs: -------------------------------------------------------------------------------- 1 | public class OrderServiceClient(HttpClient httpClient, ILogger logger) 2 | { 3 | public async Task> GetOrdersAsync(CancellationToken cancellationToken = default) 4 | { 5 | logger.LogInformation("Getting orders from {Url}", httpClient.BaseAddress); 6 | 7 | var orders = await httpClient.GetFromJsonAsync>("/orders", cancellationToken); 8 | 9 | logger.LogInformation("Got {Count} orders from {Url}", orders?.Count() ?? 0, httpClient.BaseAddress); 10 | 11 | return orders ?? Enumerable.Empty(); 12 | } 13 | 14 | public async Task MarkOrderReadyForShipment(Order order) 15 | { 16 | logger.LogInformation("Marking order {OrderId} as ready for shipment", order.OrderId); 17 | 18 | await httpClient.PutAsJsonAsync($"/orders/{order.OrderId}", order); 19 | 20 | logger.LogInformation("Marked order {OrderId} as ready for shipment", order.OrderId); 21 | } 22 | } 23 | 24 | public record CartItem(string ProductId, int Quantity = 1); 25 | 26 | public record Order(CartItem[] Cart, DateTime OrderedAt, Guid OrderId); 27 | -------------------------------------------------------------------------------- /ContosoOnline/OrderProcessor/ProductServiceClient.cs: -------------------------------------------------------------------------------- 1 | public class ProductServiceClient(ILogger logger, Products.Products.ProductsClient client) 2 | { 3 | public async Task CanInventoryFulfill(string productId, int amount) 4 | { 5 | logger.LogInformation("Checking inventory for {ProductId}", productId); 6 | 7 | var result = await client.CheckProductInventoryAsync(new Products.CheckProductInventoryRequest 8 | { 9 | ItemsRequested = amount, 10 | ProductId = productId 11 | }); 12 | 13 | logger.LogInformation("Inventory check for {ProductId} complete. Available: {IsEnoughAvailable}", productId, result.IsEnoughAvailable); 14 | 15 | return result.IsEnoughAvailable; 16 | } 17 | 18 | public async Task SubtractInventory(string productId, int amount) 19 | { 20 | logger.LogInformation("Updating inventory for {ProductId}", productId); 21 | 22 | await client.SubtractInventoryAsync(new Products.InventorySubtractionRequest 23 | { 24 | ItemsRequested = amount, 25 | ProductId = productId 26 | }); 27 | 28 | logger.LogInformation("Inventory update for {ProductId} complete.", productId); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ContosoOnline/OrderProcessor/Program.cs: -------------------------------------------------------------------------------- 1 | var builder = Host.CreateApplicationBuilder(args); 2 | 3 | builder.AddServiceDefaults(); 4 | 5 | builder.Services.AddTransient(); 6 | builder.Services.AddGrpcClient(c => c.Address = new("http://products")); 7 | builder.Services.AddHttpClient(c => c.BaseAddress = new("http://orders")); 8 | builder.Services.AddHostedService(); 9 | builder.Services.AddScoped(); 10 | 11 | var host = builder.Build(); 12 | 13 | host.Run(); 14 | 15 | -------------------------------------------------------------------------------- /ContosoOnline/OrderProcessor/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "http": { 4 | "commandName": "Project", 5 | "environmentVariables": { 6 | "DOTNET_ENVIRONMENT": "Development" 7 | }, 8 | "dotnetRunMessages": true 9 | } 10 | }, 11 | "$schema": "http://json.schemastore.org/launchsettings.json" 12 | } -------------------------------------------------------------------------------- /ContosoOnline/OrderProcessor/Protos/products.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "google/protobuf/empty.proto"; 4 | 5 | option csharp_namespace = "Products"; 6 | 7 | package products; 8 | 9 | service Products { 10 | rpc GetProducts(google.protobuf.Empty) returns (GetProductsResponse); 11 | rpc CheckProductInventory(CheckProductInventoryRequest) returns (CheckProductInventoryResponse); 12 | rpc SubtractInventory(InventorySubtractionRequest) returns (InventorySubtractionResponse); 13 | } 14 | 15 | message GetProductsResponse { 16 | repeated Product Products = 1; 17 | } 18 | 19 | message Product { 20 | string ProductId = 1; 21 | string Name = 2; 22 | float Price = 3; 23 | int32 ItemsInStock = 4; 24 | } 25 | 26 | message CheckProductInventoryRequest { 27 | string ProductId = 1; 28 | int32 ItemsRequested = 2; 29 | } 30 | 31 | message CheckProductInventoryResponse { 32 | bool IsEnoughAvailable = 1; 33 | } 34 | 35 | message InventorySubtractionRequest { 36 | string ProductId = 1; 37 | int32 ItemsRequested = 2; 38 | } 39 | 40 | message InventorySubtractionResponse { 41 | bool InventoryUpdated = 1; 42 | } -------------------------------------------------------------------------------- /ContosoOnline/OrderProcessor/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.Hosting.Lifetime": "Information" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ContosoOnline/OrderProcessor/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.Hosting.Lifetime": "Information", 6 | "System.Net.Http.HttpClient": "Warning" 7 | } 8 | }, 9 | "HttpStandardResilienceOptions": { 10 | "BulkheadOptions": { 11 | "MaxConcurrency": 1000, 12 | "MaxQueuedActions": 0 13 | }, 14 | "TotalRequestTimeoutOptions": { 15 | "TimeoutInterval": "00:00:30", 16 | "TimeoutStrategy": 0 17 | }, 18 | "RetryOptions": { 19 | "ShouldRetryAfterHeader": false, 20 | "RetryCount": 3, 21 | "BackoffType": 0, 22 | "BaseDelay": "00:00:02" 23 | }, 24 | "CircuitBreakerOptions": { 25 | "FailureThreshold": 0.1, 26 | "MinimumThroughput": 100, 27 | "BreakDuration": "00:00:05", 28 | "SamplingDuration": "00:00:30" 29 | }, 30 | "AttemptTimeoutOptions": { 31 | "TimeoutInterval": "00:00:10", 32 | "TimeoutStrategy": 0 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ContosoOnline/Orders/DatabaseInitializer.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using System.Diagnostics; 3 | 4 | namespace Orders; 5 | 6 | public class DatabaseInitializer(IServiceProvider serviceProvider, ILogger logger) : IHostedService 7 | { 8 | public const string ActivitySourceName = "Migrations"; 9 | private readonly ActivitySource _activitySource = new(ActivitySourceName); 10 | 11 | public async Task StartAsync(CancellationToken cancellationToken) => await Initialize(cancellationToken); 12 | 13 | public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; 14 | 15 | private async Task Initialize(CancellationToken cancellationToken) 16 | { 17 | using var scope = serviceProvider.CreateScope(); 18 | var dbContext = scope.ServiceProvider.GetRequiredService(); 19 | 20 | using var activity = _activitySource.StartActivity("Initializing catalog database", ActivityKind.Client); 21 | 22 | var sw = Stopwatch.StartNew(); 23 | 24 | var strategy = dbContext.Database.CreateExecutionStrategy(); 25 | await strategy.ExecuteAsync(dbContext.Database.MigrateAsync, cancellationToken); 26 | 27 | logger.LogInformation("Database initialization completed after {ElapsedMilliseconds}ms", sw.ElapsedMilliseconds); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ContosoOnline/Orders/Migrations/20240120074020_initial_create.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore.Infrastructure; 5 | using Microsoft.EntityFrameworkCore.Migrations; 6 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 7 | using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; 8 | using Orders; 9 | 10 | #nullable disable 11 | 12 | namespace Orders.Migrations 13 | { 14 | [DbContext(typeof(OrdersDbContext))] 15 | [Migration("20240120074020_initial_create")] 16 | partial class initial_create 17 | { 18 | /// 19 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 20 | { 21 | #pragma warning disable 612, 618 22 | modelBuilder 23 | .HasAnnotation("ProductVersion", "8.0.1") 24 | .HasAnnotation("Relational:MaxIdentifierLength", 63); 25 | 26 | NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); 27 | 28 | modelBuilder.Entity("Orders.CartItemDatabaseRecord", b => 29 | { 30 | b.Property("CartItemId") 31 | .ValueGeneratedOnAdd() 32 | .HasColumnType("uuid"); 33 | 34 | b.Property("OrderId") 35 | .HasColumnType("uuid"); 36 | 37 | b.Property("ProductId") 38 | .IsRequired() 39 | .HasColumnType("text"); 40 | 41 | b.Property("Quantity") 42 | .HasColumnType("integer"); 43 | 44 | b.HasKey("CartItemId"); 45 | 46 | b.ToTable("cartitems", (string)null); 47 | }); 48 | 49 | modelBuilder.Entity("Orders.OrderDatabaseRecord", b => 50 | { 51 | b.Property("OrderId") 52 | .ValueGeneratedOnAdd() 53 | .HasColumnType("uuid"); 54 | 55 | b.Property("HasShipped") 56 | .ValueGeneratedOnAdd() 57 | .HasColumnType("boolean") 58 | .HasDefaultValue(false); 59 | 60 | b.Property("OrderedAt") 61 | .HasColumnType("timestamp with time zone"); 62 | 63 | b.HasKey("OrderId"); 64 | 65 | b.ToTable("orders", (string)null); 66 | }); 67 | #pragma warning restore 612, 618 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /ContosoOnline/Orders/Migrations/20240120074020_initial_create.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | #nullable disable 5 | 6 | namespace Orders.Migrations 7 | { 8 | /// 9 | public partial class initial_create : Migration 10 | { 11 | /// 12 | protected override void Up(MigrationBuilder migrationBuilder) 13 | { 14 | migrationBuilder.CreateTable( 15 | name: "cartitems", 16 | columns: table => new 17 | { 18 | CartItemId = table.Column(type: "uuid", nullable: false), 19 | OrderId = table.Column(type: "uuid", nullable: false), 20 | ProductId = table.Column(type: "text", nullable: false), 21 | Quantity = table.Column(type: "integer", nullable: false) 22 | }, 23 | constraints: table => 24 | { 25 | table.PrimaryKey("PK_cartitems", x => x.CartItemId); 26 | }); 27 | 28 | migrationBuilder.CreateTable( 29 | name: "orders", 30 | columns: table => new 31 | { 32 | OrderId = table.Column(type: "uuid", nullable: false), 33 | OrderedAt = table.Column(type: "timestamp with time zone", nullable: false), 34 | HasShipped = table.Column(type: "boolean", nullable: false, defaultValue: false) 35 | }, 36 | constraints: table => 37 | { 38 | table.PrimaryKey("PK_orders", x => x.OrderId); 39 | }); 40 | } 41 | 42 | /// 43 | protected override void Down(MigrationBuilder migrationBuilder) 44 | { 45 | migrationBuilder.DropTable( 46 | name: "cartitems"); 47 | 48 | migrationBuilder.DropTable( 49 | name: "orders"); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ContosoOnline/Orders/Migrations/OrdersDbContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore.Infrastructure; 5 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 6 | using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; 7 | using Orders; 8 | 9 | #nullable disable 10 | 11 | namespace Orders.Migrations 12 | { 13 | [DbContext(typeof(OrdersDbContext))] 14 | partial class OrdersDbContextModelSnapshot : ModelSnapshot 15 | { 16 | protected override void BuildModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("ProductVersion", "8.0.1") 21 | .HasAnnotation("Relational:MaxIdentifierLength", 63); 22 | 23 | NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); 24 | 25 | modelBuilder.Entity("Orders.CartItemDatabaseRecord", b => 26 | { 27 | b.Property("CartItemId") 28 | .ValueGeneratedOnAdd() 29 | .HasColumnType("uuid"); 30 | 31 | b.Property("OrderId") 32 | .HasColumnType("uuid"); 33 | 34 | b.Property("ProductId") 35 | .IsRequired() 36 | .HasColumnType("text"); 37 | 38 | b.Property("Quantity") 39 | .HasColumnType("integer"); 40 | 41 | b.HasKey("CartItemId"); 42 | 43 | b.ToTable("cartitems", (string)null); 44 | }); 45 | 46 | modelBuilder.Entity("Orders.OrderDatabaseRecord", b => 47 | { 48 | b.Property("OrderId") 49 | .ValueGeneratedOnAdd() 50 | .HasColumnType("uuid"); 51 | 52 | b.Property("HasShipped") 53 | .ValueGeneratedOnAdd() 54 | .HasColumnType("boolean") 55 | .HasDefaultValue(false); 56 | 57 | b.Property("OrderedAt") 58 | .HasColumnType("timestamp with time zone"); 59 | 60 | b.HasKey("OrderId"); 61 | 62 | b.ToTable("orders", (string)null); 63 | }); 64 | #pragma warning restore 612, 618 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /ContosoOnline/Orders/Models.cs: -------------------------------------------------------------------------------- 1 | namespace Orders; 2 | 3 | public class OrderDatabaseRecord 4 | { 5 | public Guid OrderId { get; set; } 6 | public DateTime OrderedAt { get; set; } 7 | public bool HasShipped { get; set; } 8 | } 9 | 10 | public class CartItemDatabaseRecord 11 | { 12 | public Guid CartItemId { get; set; } 13 | public Guid OrderId { get; set; } 14 | public required string ProductId { get; set; } 15 | public int Quantity { get; set; } 16 | } 17 | -------------------------------------------------------------------------------- /ContosoOnline/Orders/Orders.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | true 8 | Linux 9 | True 10 | preview 11 | bf570ad3-c0cc-4ae2-ab71-2e2adb1fc8b4 12 | 13 | 14 | 15 | 16 | 18 | 19 | runtime; build; native; contentfiles; analyzers; buildtransitive 20 | all 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /ContosoOnline/Orders/OrdersApi.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http.HttpResults; 2 | 3 | namespace Orders; 4 | 5 | public static class OrdersApi 6 | { 7 | public static RouteGroupBuilder MapOrdersApi(this IEndpointRouteBuilder routes) 8 | { 9 | var group = routes.MapGroup("/orders"); 10 | 11 | group.MapGet("/", async (OrdersDbContext dbContext) => 12 | { 13 | var orders = (dbContext.OrderItems.Where(x => x.HasShipped == false).ToList()).Select(p => new Order(p.OrderedAt, p.OrderId)).ToList(); 14 | 15 | var cartItems = (dbContext.CartItems.ToList()).ToList(); 16 | 17 | orders.ForEach(o => o.Cart = 18 | cartItems.Where(c => c.OrderId == o.OrderId) 19 | .Select(c => new CartItem(c.ProductId, c.Quantity)).ToArray()); 20 | 21 | return orders; 22 | }); 23 | 24 | group.MapPost("/", async Task>> (OrdersDbContext dbContext, Order order, CancellationToken ct) => 25 | { 26 | var newOrder = new OrderDatabaseRecord 27 | { 28 | OrderId = order.OrderId, 29 | OrderedAt = DateTime.UtcNow, 30 | HasShipped = false 31 | }; 32 | 33 | dbContext.OrderItems.Add(newOrder); 34 | await dbContext.SaveChangesAsync(ct); 35 | 36 | if (newOrder is null) 37 | { 38 | return TypedResults.BadRequest(); 39 | } 40 | 41 | if (order.Cart is not null) 42 | { 43 | foreach (var item in order.Cart) 44 | { 45 | var newCartItem = new CartItemDatabaseRecord 46 | { 47 | CartItemId = Guid.NewGuid(), 48 | OrderId = order.OrderId, 49 | ProductId = item.ProductId, 50 | Quantity = item.Quantity 51 | }; 52 | 53 | dbContext.CartItems.Add(newCartItem); 54 | await dbContext.SaveChangesAsync(ct); 55 | } 56 | } 57 | 58 | return TypedResults.Created($"/orders", new Order(newOrder.OrderedAt, newOrder.OrderId)); 59 | }); 60 | 61 | group.MapPut("/{orderId}", async Task> (OrdersDbContext dbContext, Guid orderId, Order order) => 62 | { 63 | var b = dbContext.OrderItems.FirstOrDefault(x => x.OrderId == orderId); 64 | if (b is not null) 65 | { 66 | b.HasShipped = true; 67 | dbContext.Update(b); 68 | await dbContext.SaveChangesAsync(); 69 | return TypedResults.NoContent(); 70 | } 71 | 72 | return TypedResults.NotFound(); 73 | }); 74 | 75 | return group; 76 | } 77 | } 78 | 79 | public record CartItem(string ProductId, int Quantity = 1); 80 | 81 | public record Order(DateTime OrderedAt, Guid OrderId) 82 | { 83 | public bool HasShipped { get; set; } 84 | public CartItem[]? Cart { get; set; } 85 | } 86 | -------------------------------------------------------------------------------- /ContosoOnline/Orders/OrdersDbContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Metadata.Builders; 2 | using Microsoft.EntityFrameworkCore; 3 | 4 | namespace Orders; 5 | 6 | public class OrdersDbContext(DbContextOptions options) : DbContext(options) 7 | { 8 | public DbSet OrderItems => Set(); 9 | public DbSet CartItems => Set(); 10 | 11 | protected override void OnModelCreating(ModelBuilder builder) 12 | { 13 | DefineOrderRecord(builder.Entity()); 14 | 15 | DefineCartItemRecord(builder.Entity()); 16 | } 17 | 18 | private static void DefineOrderRecord(EntityTypeBuilder builder) 19 | { 20 | builder.ToTable("orders"); 21 | 22 | builder.HasKey(ci => ci.OrderId); 23 | 24 | builder.Property(ci => ci.OrderId) 25 | .IsRequired(); 26 | 27 | builder.Property(cb => cb.OrderedAt) 28 | .IsRequired(); 29 | 30 | builder.Property(cc => cc.HasShipped) 31 | .IsRequired() 32 | .HasDefaultValue(false); 33 | } 34 | 35 | private static void DefineCartItemRecord(EntityTypeBuilder builder) 36 | { 37 | builder.ToTable("cartitems"); 38 | 39 | builder.HasKey(ci => ci.CartItemId); 40 | 41 | builder.Property(ci => ci.CartItemId) 42 | .IsRequired(); 43 | 44 | builder.Property(ci => ci.ProductId) 45 | .IsRequired(); 46 | 47 | builder.Property(ci => ci.OrderId) 48 | .IsRequired(); 49 | 50 | builder.Property(ci => ci.Quantity) 51 | .IsRequired(); 52 | } 53 | 54 | private static async Task> ToListAsync(IAsyncEnumerable asyncEnumerable) 55 | { 56 | var results = new List(); 57 | await foreach (var value in asyncEnumerable) 58 | { 59 | results.Add(value); 60 | } 61 | 62 | return results; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /ContosoOnline/Orders/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Orders; 3 | 4 | var builder = WebApplication.CreateBuilder(args); 5 | 6 | builder.AddServiceDefaults(); 7 | builder.AddNpgsqlDbContext("ordersdb", null, 8 | optionsBuilder => optionsBuilder.UseNpgsql(npgsqlBuilder => 9 | npgsqlBuilder.MigrationsAssembly(typeof(Program).Assembly.GetName().Name))); 10 | builder.Services.AddSingleton(); 11 | builder.Services.AddHostedService(sp => sp.GetRequiredService()); 12 | builder.Services.AddEndpointsApiExplorer(); 13 | builder.Services.AddSwaggerGen(); 14 | 15 | var app = builder.Build(); 16 | 17 | app.MapDefaultEndpoints(); 18 | 19 | app.MapGet("/", () => "Orders"); 20 | 21 | if (app.Environment.IsDevelopment()) 22 | { 23 | app.MapGet("/envvars", () => 24 | { 25 | var envVars = Environment.GetEnvironmentVariables(); 26 | var envVarsString = string.Join("\n", envVars.Keys.Cast().Select(key => $"{key}={envVars[key]}")); 27 | return envVarsString; 28 | }); 29 | 30 | app.UseSwagger(); 31 | app.UseSwaggerUI(); 32 | } 33 | 34 | app.MapOrdersApi(); 35 | 36 | app.Run(); 37 | -------------------------------------------------------------------------------- /ContosoOnline/Orders/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "http": { 4 | "commandName": "Project", 5 | "launchBrowser": false, 6 | "launchUrl": "orders", 7 | "environmentVariables": { 8 | "ASPNETCORE_ENVIRONMENT": "Development" 9 | }, 10 | "dotnetRunMessages": true, 11 | "applicationUrl": "http://localhost:5004" 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /ContosoOnline/Orders/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning", 6 | "System.Net.Http.HttpClient": "Warning" 7 | } 8 | }, 9 | "AllowedHosts": "*", 10 | "ConnectionStrings": { 11 | // A connection string is here to enable use of the `dotnet ef` cmd line tool from the project root. 12 | // If the configuration value is not present or not well-formed, the app will fail at startup. 13 | // Note that some commands require the connection string to point to a real database in order to fully 14 | // function (e.g. `dotnet ef database update`, `dotnet ef migrations list`). 15 | "ordersdb": "Server=localhost;Port=5432;Database=NOT_A_REAL_DB" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ContosoOnline/Products/ProductServices.cs: -------------------------------------------------------------------------------- 1 | namespace Products; 2 | 3 | public interface IProductService 4 | { 5 | public Task GetProductsAsync(); 6 | public Task CheckProductInventoryAsync(string productId, int quantityNeeded); 7 | public Task SubtractInventory(string productId, int quantityNeeded); 8 | } 9 | 10 | public class FakeProductService(ILogger logger) : IProductService 11 | { 12 | private List _fakeOrders = new() 13 | { 14 | new () { Name = "Apple", Price = 0.99f, ItemsInStock = 25, ProductId = "01" }, 15 | new () { Name = "Banana", Price = 0.99f, ItemsInStock = 25, ProductId = "02" }, 16 | new () { Name = "Orange", Price = 0.99f, ItemsInStock = 25, ProductId = "03" }, 17 | new () { Name = "Pear", Price = 0.99f, ItemsInStock = 25, ProductId = "04" }, 18 | new () { Name = "Pineapple", Price = 0.99f, ItemsInStock = 25, ProductId = "05" } 19 | }; 20 | 21 | public Task GetProductsAsync() 22 | { 23 | var productsInStock = _fakeOrders?.Where(p => p.ItemsInStock > 0).ToArray(); 24 | return Task.FromResult(productsInStock); 25 | } 26 | 27 | public Task CheckProductInventoryAsync(string productId, int quantityNeeded) 28 | { 29 | logger.LogInformation("Checking inventory for {ProductId} with quantity {QuantityNeeded}", productId, quantityNeeded); 30 | 31 | bool isEnoughInStock = _fakeOrders?.FirstOrDefault(p => p.ProductId == productId)?.ItemsInStock >= quantityNeeded; 32 | 33 | logger.LogInformation("Are enough items in stock for Product {ProductId}: {IsEnoughInStock}", productId, isEnoughInStock); 34 | 35 | return Task.FromResult(isEnoughInStock); 36 | } 37 | 38 | public Task SubtractInventory(string productId, int quantityNeeded) 39 | { 40 | logger.LogInformation("Subtracting {QuantityNeeded} from {ProductId} inventory", quantityNeeded, productId); 41 | 42 | var product = _fakeOrders.FirstOrDefault(p => p.ProductId == productId); 43 | if (product != null) 44 | { 45 | logger.LogInformation("Found product {Name} with {ItemsInStock} in stock", product.Name, product.ItemsInStock); 46 | 47 | product.ItemsInStock -= quantityNeeded; 48 | _fakeOrders.RemoveAll(p => p.ProductId == productId); 49 | _fakeOrders.Add(product); 50 | 51 | logger.LogInformation("Subtracted {QuantityNeeded} from {Name} inventory. New inventory is {ItemsInStock}", quantityNeeded, product.Name, product.ItemsInStock); 52 | 53 | return Task.FromResult(true); 54 | } 55 | else 56 | { 57 | logger.LogError("Unable to find product with id {ProductId}", productId); 58 | 59 | return Task.FromResult(false); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /ContosoOnline/Products/Products.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | true 8 | 8f201042-cefe-43d4-898a-b9458cdf5a87 9 | Linux 10 | preview 11 | true 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /ContosoOnline/Products/ProductsGrpcService.cs: -------------------------------------------------------------------------------- 1 | using Google.Protobuf.WellKnownTypes; 2 | using Grpc.Core; 3 | 4 | namespace Products; 5 | 6 | public class ProductsGrpcService(IProductService productService) : Products.ProductsBase 7 | { 8 | public override async Task GetProducts(Empty request, ServerCallContext context) 9 | { 10 | var products = await productService.GetProductsAsync(); 11 | return new GetProductsResponse { Products = { products } }; 12 | } 13 | 14 | public override async Task CheckProductInventory(CheckProductInventoryRequest request, ServerCallContext context) 15 | { 16 | var inventory = await productService.CheckProductInventoryAsync(request.ProductId, request.ItemsRequested); 17 | return new CheckProductInventoryResponse { IsEnoughAvailable = inventory }; 18 | } 19 | 20 | public override async Task SubtractInventory(InventorySubtractionRequest request, ServerCallContext context) 21 | { 22 | var result = await productService.SubtractInventory(request.ProductId, request.ItemsRequested); 23 | return new InventorySubtractionResponse { InventoryUpdated = result }; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ContosoOnline/Products/Program.cs: -------------------------------------------------------------------------------- 1 | using Products; 2 | 3 | var builder = WebApplication.CreateBuilder(args); 4 | 5 | builder.AddServiceDefaults(); 6 | builder.Services.AddGrpc(); 7 | builder.Services.AddSingleton(); 8 | 9 | var app = builder.Build(); 10 | 11 | app.MapGrpcService(); 12 | 13 | app.MapDefaultEndpoints(); 14 | 15 | app.Run(); -------------------------------------------------------------------------------- /ContosoOnline/Products/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "http": { 4 | "commandName": "Project", 5 | "dotnetRunMessages": true, 6 | "launchBrowser": false, 7 | "launchUrl": "", 8 | "applicationUrl": "http://localhost:5309", 9 | "environmentVariables": { 10 | "ASPNETCORE_ENVIRONMENT": "Development" 11 | } 12 | }, 13 | "https": { 14 | "commandName": "Project", 15 | "dotnetRunMessages": true, 16 | "launchBrowser": false, 17 | "launchUrl": "", 18 | "applicationUrl": "https://localhost:7309;http://localhost:5309", 19 | "environmentVariables": { 20 | "ASPNETCORE_ENVIRONMENT": "Development" 21 | } 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /ContosoOnline/Products/Protos/products.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "google/protobuf/empty.proto"; 4 | 5 | option csharp_namespace = "Products"; 6 | 7 | package products; 8 | 9 | service Products { 10 | rpc GetProducts(google.protobuf.Empty) returns (GetProductsResponse); 11 | rpc CheckProductInventory(CheckProductInventoryRequest) returns (CheckProductInventoryResponse); 12 | rpc SubtractInventory(InventorySubtractionRequest) returns (InventorySubtractionResponse); 13 | } 14 | 15 | message GetProductsResponse { 16 | repeated Product Products = 1; 17 | } 18 | 19 | message Product { 20 | string ProductId = 1; 21 | string Name = 2; 22 | float Price = 3; 23 | int32 ItemsInStock = 4; 24 | } 25 | 26 | message CheckProductInventoryRequest { 27 | string ProductId = 1; 28 | int32 ItemsRequested = 2; 29 | } 30 | 31 | message CheckProductInventoryResponse { 32 | bool IsEnoughAvailable = 1; 33 | } 34 | 35 | message InventorySubtractionRequest { 36 | string ProductId = 1; 37 | int32 ItemsRequested = 2; 38 | } 39 | 40 | message InventorySubtractionResponse { 41 | bool InventoryUpdated = 1; 42 | } -------------------------------------------------------------------------------- /ContosoOnline/Products/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning", 6 | "System.Net.Http.HttpClient": "Warning" 7 | } 8 | }, 9 | "AllowedHosts": "*", 10 | "Kestrel": { 11 | "EndpointDefaults": { 12 | "Protocols": "Http2" 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ContosoOnline/Store/App.razor: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | Not found 8 | 9 |

Sorry, there's nothing at this address.

10 |
11 |
12 |
13 | -------------------------------------------------------------------------------- /ContosoOnline/Store/Pages/Error.cshtml: -------------------------------------------------------------------------------- 1 | @page 2 | @model Store.Pages.ErrorModel 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Error 11 | 12 | 13 | 14 | 15 | 16 |
17 |
18 |

Error.

19 |

An error occurred while processing your request.

20 | 21 | @if (Model.ShowRequestId) 22 | { 23 |

24 | Request ID: @Model.RequestId 25 |

26 | } 27 | 28 |

Development Mode

29 |

30 | Swapping to the Development environment displays detailed information about the error that occurred. 31 |

32 |

33 | The Development environment shouldn't be enabled for deployed applications. 34 | It can result in displaying sensitive information from exceptions to end users. 35 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 36 | and restarting the app. 37 |

38 |
39 |
40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /ContosoOnline/Store/Pages/Error.cshtml.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.AspNetCore.Mvc.RazorPages; 3 | using System.Diagnostics; 4 | 5 | namespace Store.Pages 6 | { 7 | [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] 8 | [IgnoreAntiforgeryToken] 9 | public class ErrorModel : PageModel 10 | { 11 | public string? RequestId { get; set; } 12 | 13 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 14 | 15 | private readonly ILogger _logger; 16 | 17 | public ErrorModel(ILogger logger) 18 | { 19 | _logger = logger; 20 | } 21 | 22 | public void OnGet() 23 | { 24 | RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /ContosoOnline/Store/Pages/Index.razor: -------------------------------------------------------------------------------- 1 | @page "/" 2 | @using Google.Protobuf.WellKnownTypes; 3 | @using Grpc.Net.Client; 4 | @using Products; 5 | @inject Products.ProductsClient _productsClient; 6 | @inject OrderServiceClient _orderClient; 7 | 8 | Contoso Online 9 | 10 | Contoso Online 11 | Welcome to Contoso Online 12 | Below you will find all of the products currently in stock. Use the "Order" button below to add it to your cart, then click the "Submit Order" button to send the order to us to fulfill it. 13 | 14 | @if (_grpcWorking) 15 | { 16 | 17 | 18 | Product 19 | Price 20 | In Stock? 21 | Order 22 | 23 | 24 | @context.Name 25 | @context.Price 26 | @context.ItemsInStock 27 | 28 | @if (!_cart.Any(x => x.ProductId == context.ProductId)) 29 | { 30 | Add to Cart 31 | } 32 | else 33 | { 34 | @(_cart.First(x => x.ProductId == context.ProductId).Quantity) in cart 35 | } 36 | 37 | 38 | 39 | 40 | 41 | @if (_processing) 42 | { 43 | 44 | Processing 45 | } 46 | else 47 | { 48 | Submit Order 49 | } 50 | 51 | 52 | 53 | 54 | } 55 | else 56 | { 57 | Product gRPC Error 58 | @_error 59 | 60 | } 61 | 62 | 63 | @code 64 | { 65 | private List _products = new List(); 66 | private List _cart = new List(); 67 | private bool _shouldRender; 68 | private bool _processing = false; 69 | private bool _grpcWorking = false; 70 | private string? _error = null; 71 | 72 | override protected bool ShouldRender() => _shouldRender; 73 | 74 | override protected async Task OnInitializedAsync() 75 | { 76 | try 77 | { 78 | await GetProducts(); 79 | _grpcWorking = true; 80 | } 81 | catch(Exception ex) 82 | { 83 | _error = ex.ToString(); 84 | _grpcWorking = false; 85 | } 86 | 87 | _shouldRender = true; 88 | } 89 | 90 | protected async Task GetProducts() 91 | { 92 | var reply = await _productsClient.GetProductsAsync(new Empty()); 93 | var products = reply.Products.ToList(); 94 | 95 | _products.Clear(); 96 | 97 | foreach (var item in products.OrderBy(x => x.Name)) 98 | { 99 | _products.Add(item); 100 | } 101 | } 102 | 103 | protected void AddToCart(Product product) 104 | { 105 | if(!_cart.Any(x => x.ProductId == product.ProductId)) 106 | { 107 | _cart.Add(new CartItem(product.ProductId) { Quantity = 1}); 108 | } 109 | else 110 | { 111 | _cart.First(x => x.ProductId == product.ProductId).Quantity++; 112 | } 113 | 114 | StateHasChanged(); 115 | } 116 | 117 | protected async Task SubmitOrder() 118 | { 119 | _processing = true; 120 | StateHasChanged(); 121 | 122 | var result = await _orderClient.SubmitNewOrder(_cart.ToArray()); 123 | _cart.Clear(); 124 | await GetProducts(); 125 | 126 | _processing = false; 127 | StateHasChanged(); 128 | } 129 | } -------------------------------------------------------------------------------- /ContosoOnline/Store/Pages/_Host.cshtml: -------------------------------------------------------------------------------- 1 | @page "/" 2 | @using Microsoft.AspNetCore.Components.Web 3 | @namespace Store.Pages 4 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | An error has occurred. This application may no longer respond until reloaded. 26 | 27 | 28 | An unhandled exception has occurred. See browser dev tools for details. 29 | 30 | Reload 31 | 🗙 32 |
33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /ContosoOnline/Store/Program.cs: -------------------------------------------------------------------------------- 1 | using MudBlazor.Services; 2 | using Store; 3 | 4 | var builder = WebApplication.CreateBuilder(args); 5 | 6 | builder.AddServiceDefaults(); 7 | builder.Services.AddGrpcClient(c => c.Address = new("http://products")); 8 | builder.Services.AddHttpClient(c => c.BaseAddress = new("http://orders")); 9 | builder.Services.AddRazorPages(); 10 | builder.Services.AddServerSideBlazor(); 11 | builder.Services.AddMudServices(); 12 | 13 | var app = builder.Build(); 14 | 15 | app.MapDefaultEndpoints(); 16 | 17 | if (!app.Environment.IsDevelopment()) 18 | { 19 | app.UseExceptionHandler("/Error"); 20 | app.UseHsts(); 21 | } 22 | 23 | app.UseStaticFiles(); 24 | app.UseRouting(); 25 | app.MapBlazorHub(); 26 | app.MapFallbackToPage("/_Host"); 27 | 28 | app.Run(); 29 | -------------------------------------------------------------------------------- /ContosoOnline/Store/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "http": { 4 | "commandName": "Project", 5 | "environmentVariables": { 6 | "ASPNETCORE_ENVIRONMENT": "Development" 7 | }, 8 | "launchBrowser": false, 9 | "dotnetRunMessages": true, 10 | "applicationUrl": "http://localhost:5176" 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /ContosoOnline/Store/Protos/products.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "google/protobuf/empty.proto"; 4 | 5 | option csharp_namespace = "Products"; 6 | 7 | package products; 8 | 9 | service Products { 10 | rpc GetProducts(google.protobuf.Empty) returns (GetProductsResponse); 11 | rpc CheckProductInventory(CheckProductInventoryRequest) returns (CheckProductInventoryResponse); 12 | rpc SubtractInventory(InventorySubtractionRequest) returns (InventorySubtractionResponse); 13 | } 14 | 15 | message GetProductsResponse { 16 | repeated Product Products = 1; 17 | } 18 | 19 | message Product { 20 | string ProductId = 1; 21 | string Name = 2; 22 | float Price = 3; 23 | int32 ItemsInStock = 4; 24 | } 25 | 26 | message CheckProductInventoryRequest { 27 | string ProductId = 1; 28 | int32 ItemsRequested = 2; 29 | } 30 | 31 | message CheckProductInventoryResponse { 32 | bool IsEnoughAvailable = 1; 33 | } 34 | 35 | message InventorySubtractionRequest { 36 | string ProductId = 1; 37 | int32 ItemsRequested = 2; 38 | } 39 | 40 | message InventorySubtractionResponse { 41 | bool InventoryUpdated = 1; 42 | } -------------------------------------------------------------------------------- /ContosoOnline/Store/Services/OrderServiceClient.cs: -------------------------------------------------------------------------------- 1 | namespace Store; 2 | 3 | public class OrderServiceClient(HttpClient httpClient, ILogger logger) 4 | { 5 | public async Task SubmitNewOrder(CartItem[] cart) 6 | { 7 | var orderId = Guid.NewGuid(); 8 | 9 | logger.LogInformation("Submitting new order {OrderId} to {Url}", orderId, httpClient.BaseAddress); 10 | 11 | var order = new Order(cart, DateTime.UtcNow, orderId); 12 | 13 | var response = await httpClient.PostAsJsonAsync("/orders", order); 14 | 15 | if (response.IsSuccessStatusCode) 16 | { 17 | logger.LogInformation("Successfully submitted order {orderId} to {Url}", order, httpClient.BaseAddress); 18 | return true; 19 | } 20 | 21 | logger.LogError("Failed to submit order {OrderId} to {Url}", orderId, httpClient.BaseAddress); 22 | return false; 23 | } 24 | } 25 | 26 | public record CartItem(string ProductId) 27 | { 28 | public int Quantity { get; set; } 29 | } 30 | 31 | public record Order(CartItem[] Cart, DateTime OrderedAt, Guid OrderId); 32 | -------------------------------------------------------------------------------- /ContosoOnline/Store/Shared/MainLayout.razor: -------------------------------------------------------------------------------- 1 | @inherits LayoutComponentBase 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Contoso Online 17 | 18 | 19 | 20 | 21 | 22 | @Body 23 | 24 | 25 | 26 | 27 | @code { 28 | bool _drawerOpen = false; 29 | 30 | void DrawerToggle() 31 | { 32 | _drawerOpen = !_drawerOpen; 33 | } 34 | } -------------------------------------------------------------------------------- /ContosoOnline/Store/Shared/MainLayout.razor.css: -------------------------------------------------------------------------------- 1 | .page { 2 | position: relative; 3 | display: flex; 4 | flex-direction: column; 5 | } 6 | 7 | main { 8 | flex: 1; 9 | } 10 | 11 | .sidebar { 12 | background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%); 13 | } 14 | 15 | .top-row { 16 | background-color: #f7f7f7; 17 | border-bottom: 1px solid #d6d5d5; 18 | justify-content: flex-end; 19 | height: 3.5rem; 20 | display: flex; 21 | align-items: center; 22 | } 23 | 24 | .top-row ::deep a, .top-row .btn-link { 25 | white-space: nowrap; 26 | margin-left: 1.5rem; 27 | } 28 | 29 | .top-row a:first-child { 30 | overflow: hidden; 31 | text-overflow: ellipsis; 32 | } 33 | 34 | @media (max-width: 640.98px) { 35 | .top-row:not(.auth) { 36 | display: none; 37 | } 38 | 39 | .top-row.auth { 40 | justify-content: space-between; 41 | } 42 | 43 | .top-row a, .top-row .btn-link { 44 | margin-left: 0; 45 | } 46 | } 47 | 48 | @media (min-width: 641px) { 49 | .page { 50 | flex-direction: row; 51 | } 52 | 53 | .sidebar { 54 | width: 250px; 55 | height: 100vh; 56 | position: sticky; 57 | top: 0; 58 | } 59 | 60 | .top-row { 61 | position: sticky; 62 | top: 0; 63 | z-index: 1; 64 | } 65 | 66 | .top-row, article { 67 | padding-left: 2rem !important; 68 | padding-right: 1.5rem !important; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /ContosoOnline/Store/Shared/NavMenu.razor: -------------------------------------------------------------------------------- 1 |  2 | Products 3 | Orders 4 | 5 | -------------------------------------------------------------------------------- /ContosoOnline/Store/Shared/NavMenu.razor.css: -------------------------------------------------------------------------------- 1 | .navbar-toggler { 2 | background-color: rgba(255, 255, 255, 0.1); 3 | } 4 | 5 | .top-row { 6 | height: 3.5rem; 7 | background-color: rgba(0,0,0,0.4); 8 | } 9 | 10 | .navbar-brand { 11 | font-size: 1.1rem; 12 | } 13 | 14 | .oi { 15 | width: 2rem; 16 | font-size: 1.1rem; 17 | vertical-align: text-top; 18 | top: -2px; 19 | } 20 | 21 | .nav-item { 22 | font-size: 0.9rem; 23 | padding-bottom: 0.5rem; 24 | } 25 | 26 | .nav-item:first-of-type { 27 | padding-top: 1rem; 28 | } 29 | 30 | .nav-item:last-of-type { 31 | padding-bottom: 1rem; 32 | } 33 | 34 | .nav-item ::deep a { 35 | color: #d7d7d7; 36 | border-radius: 4px; 37 | height: 3rem; 38 | display: flex; 39 | align-items: center; 40 | line-height: 3rem; 41 | } 42 | 43 | .nav-item ::deep a.active { 44 | background-color: rgba(255,255,255,0.25); 45 | color: white; 46 | } 47 | 48 | .nav-item ::deep a:hover { 49 | background-color: rgba(255,255,255,0.1); 50 | color: white; 51 | } 52 | 53 | @media (min-width: 641px) { 54 | .navbar-toggler { 55 | display: none; 56 | } 57 | 58 | .collapse { 59 | /* Never collapse the sidebar for wide screens */ 60 | display: block; 61 | } 62 | 63 | .nav-scrollable { 64 | /* Allow sidebar to scroll for tall menus */ 65 | height: calc(100vh - 3.5rem); 66 | overflow-y: auto; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /ContosoOnline/Store/Store.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8c1fa008-f58d-4e3c-87e1-4bd2b50b97eb 8 | Linux 9 | True 10 | preview 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /ContosoOnline/Store/_Imports.razor: -------------------------------------------------------------------------------- 1 | @using System.Net.Http 2 | @using Microsoft.AspNetCore.Authorization 3 | @using Microsoft.AspNetCore.Components.Authorization 4 | @using Microsoft.AspNetCore.Components.Forms 5 | @using Microsoft.AspNetCore.Components.Routing 6 | @using Microsoft.AspNetCore.Components.Web 7 | @using Microsoft.AspNetCore.Components.Web.Virtualization 8 | @using Microsoft.JSInterop 9 | @using Store 10 | @using Store.Shared 11 | @using MudBlazor 12 | @using MudBlazor.Services 13 | @using Grpc.Core; 14 | @using Grpc.Net.Client; -------------------------------------------------------------------------------- /ContosoOnline/Store/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "DetailedErrors": true, 3 | "Logging": { 4 | "LogLevel": { 5 | "Default": "Information", 6 | "Microsoft.AspNetCore": "Warning" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /ContosoOnline/Store/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning", 6 | "System.Net.Http.HttpClient": "Warning" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /ContosoOnline/Store/wwwroot/css/open-iconic/FONT-LICENSE: -------------------------------------------------------------------------------- 1 | SIL OPEN FONT LICENSE Version 1.1 2 | 3 | Copyright (c) 2014 Waybury 4 | 5 | PREAMBLE 6 | The goals of the Open Font License (OFL) are to stimulate worldwide 7 | development of collaborative font projects, to support the font creation 8 | efforts of academic and linguistic communities, and to provide a free and 9 | open framework in which fonts may be shared and improved in partnership 10 | with others. 11 | 12 | The OFL allows the licensed fonts to be used, studied, modified and 13 | redistributed freely as long as they are not sold by themselves. The 14 | fonts, including any derivative works, can be bundled, embedded, 15 | redistributed and/or sold with any software provided that any reserved 16 | names are not used by derivative works. The fonts and derivatives, 17 | however, cannot be released under any other type of license. The 18 | requirement for fonts to remain under this license does not apply 19 | to any document created using the fonts or their derivatives. 20 | 21 | DEFINITIONS 22 | "Font Software" refers to the set of files released by the Copyright 23 | Holder(s) under this license and clearly marked as such. This may 24 | include source files, build scripts and documentation. 25 | 26 | "Reserved Font Name" refers to any names specified as such after the 27 | copyright statement(s). 28 | 29 | "Original Version" refers to the collection of Font Software components as 30 | distributed by the Copyright Holder(s). 31 | 32 | "Modified Version" refers to any derivative made by adding to, deleting, 33 | or substituting -- in part or in whole -- any of the components of the 34 | Original Version, by changing formats or by porting the Font Software to a 35 | new environment. 36 | 37 | "Author" refers to any designer, engineer, programmer, technical 38 | writer or other person who contributed to the Font Software. 39 | 40 | PERMISSION & CONDITIONS 41 | Permission is hereby granted, free of charge, to any person obtaining 42 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 43 | redistribute, and sell modified and unmodified copies of the Font 44 | Software, subject to the following conditions: 45 | 46 | 1) Neither the Font Software nor any of its individual components, 47 | in Original or Modified Versions, may be sold by itself. 48 | 49 | 2) Original or Modified Versions of the Font Software may be bundled, 50 | redistributed and/or sold with any software, provided that each copy 51 | contains the above copyright notice and this license. These can be 52 | included either as stand-alone text files, human-readable headers or 53 | in the appropriate machine-readable metadata fields within text or 54 | binary files as long as those fields can be easily viewed by the user. 55 | 56 | 3) No Modified Version of the Font Software may use the Reserved Font 57 | Name(s) unless explicit written permission is granted by the corresponding 58 | Copyright Holder. This restriction only applies to the primary font name as 59 | presented to the users. 60 | 61 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 62 | Software shall not be used to promote, endorse or advertise any 63 | Modified Version, except to acknowledge the contribution(s) of the 64 | Copyright Holder(s) and the Author(s) or with their explicit written 65 | permission. 66 | 67 | 5) The Font Software, modified or unmodified, in part or in whole, 68 | must be distributed entirely under this license, and must not be 69 | distributed under any other license. The requirement for fonts to 70 | remain under this license does not apply to any document created 71 | using the Font Software. 72 | 73 | TERMINATION 74 | This license becomes null and void if any of the above conditions are 75 | not met. 76 | 77 | DISCLAIMER 78 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 79 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 80 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 81 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 82 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 83 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 84 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 85 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 86 | OTHER DEALINGS IN THE FONT SOFTWARE. 87 | -------------------------------------------------------------------------------- /ContosoOnline/Store/wwwroot/css/open-iconic/ICON-LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Waybury 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 13 | all 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 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /ContosoOnline/Store/wwwroot/css/open-iconic/README.md: -------------------------------------------------------------------------------- 1 | [Open Iconic v1.1.1](http://useiconic.com/open) 2 | =========== 3 | 4 | ### Open Iconic is the open source sibling of [Iconic](http://useiconic.com). It is a hyper-legible collection of 223 icons with a tiny footprint—ready to use with Bootstrap and Foundation. [View the collection](http://useiconic.com/open#icons) 5 | 6 | 7 | 8 | ## What's in Open Iconic? 9 | 10 | * 223 icons designed to be legible down to 8 pixels 11 | * Super-light SVG files - 61.8 for the entire set 12 | * SVG sprite—the modern replacement for icon fonts 13 | * Webfont (EOT, OTF, SVG, TTF, WOFF), PNG and WebP formats 14 | * Webfont stylesheets (including versions for Bootstrap and Foundation) in CSS, LESS, SCSS and Stylus formats 15 | * PNG and WebP raster images in 8px, 16px, 24px, 32px, 48px and 64px. 16 | 17 | 18 | ## Getting Started 19 | 20 | #### For code samples and everything else you need to get started with Open Iconic, check out our [Icons](http://useiconic.com/open#icons) and [Reference](http://useiconic.com/open#reference) sections. 21 | 22 | ### General Usage 23 | 24 | #### Using Open Iconic's SVGs 25 | 26 | We like SVGs and we think they're the way to display icons on the web. Since Open Iconic are just basic SVGs, we suggest you display them like you would any other image (don't forget the `alt` attribute). 27 | 28 | ``` 29 | icon name 30 | ``` 31 | 32 | #### Using Open Iconic's SVG Sprite 33 | 34 | Open Iconic also comes in a SVG sprite which allows you to display all the icons in the set with a single request. It's like an icon font, without being a hack. 35 | 36 | Adding an icon from an SVG sprite is a little different than what you're used to, but it's still a piece of cake. *Tip: To make your icons easily style able, we suggest adding a general class to the* `` *tag and a unique class name for each different icon in the* `` *tag.* 37 | 38 | ``` 39 | 40 | 41 | 42 | ``` 43 | 44 | Sizing icons only needs basic CSS. All the icons are in a square format, so just set the `` tag with equal width and height dimensions. 45 | 46 | ``` 47 | .icon { 48 | width: 16px; 49 | height: 16px; 50 | } 51 | ``` 52 | 53 | Coloring icons is even easier. All you need to do is set the `fill` rule on the `` tag. 54 | 55 | ``` 56 | .icon-account-login { 57 | fill: #f00; 58 | } 59 | ``` 60 | 61 | To learn more about SVG Sprites, read [Chris Coyier's guide](http://css-tricks.com/svg-sprites-use-better-icon-fonts/). 62 | 63 | #### Using Open Iconic's Icon Font... 64 | 65 | 66 | ##### …with Bootstrap 67 | 68 | You can find our Bootstrap stylesheets in `font/css/open-iconic-bootstrap.{css, less, scss, styl}` 69 | 70 | 71 | ``` 72 | 73 | ``` 74 | 75 | 76 | ``` 77 | 78 | ``` 79 | 80 | ##### …with Foundation 81 | 82 | You can find our Foundation stylesheets in `font/css/open-iconic-foundation.{css, less, scss, styl}` 83 | 84 | ``` 85 | 86 | ``` 87 | 88 | 89 | ``` 90 | 91 | ``` 92 | 93 | ##### …on its own 94 | 95 | You can find our default stylesheets in `font/css/open-iconic.{css, less, scss, styl}` 96 | 97 | ``` 98 | 99 | ``` 100 | 101 | ``` 102 | 103 | ``` 104 | 105 | 106 | ## License 107 | 108 | ### Icons 109 | 110 | All code (including SVG markup) is under the [MIT License](http://opensource.org/licenses/MIT). 111 | 112 | ### Fonts 113 | 114 | All fonts are under the [SIL Licensed](http://scripts.sil.org/cms/scripts/page.php?item_id=OFL_web). 115 | -------------------------------------------------------------------------------- /ContosoOnline/Store/wwwroot/css/open-iconic/font/css/open-iconic-bootstrap.min.css: -------------------------------------------------------------------------------- 1 | @font-face{font-family:Icons;src:url(../fonts/open-iconic.eot);src:url(../fonts/open-iconic.eot?#iconic-sm) format('embedded-opentype'),url(../fonts/open-iconic.woff) format('woff'),url(../fonts/open-iconic.ttf) format('truetype'),url(../fonts/open-iconic.otf) format('opentype'),url(../fonts/open-iconic.svg#iconic-sm) format('svg');font-weight:400;font-style:normal}.oi{position:relative;top:1px;display:inline-block;speak:none;font-family:Icons;font-style:normal;font-weight:400;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.oi:empty:before{width:1em;text-align:center;box-sizing:content-box}.oi.oi-align-center:before{text-align:center}.oi.oi-align-left:before{text-align:left}.oi.oi-align-right:before{text-align:right}.oi.oi-flip-horizontal:before{-webkit-transform:scale(-1,1);-ms-transform:scale(-1,1);transform:scale(-1,1)}.oi.oi-flip-vertical:before{-webkit-transform:scale(1,-1);-ms-transform:scale(-1,1);transform:scale(1,-1)}.oi.oi-flip-horizontal-vertical:before{-webkit-transform:scale(-1,-1);-ms-transform:scale(-1,1);transform:scale(-1,-1)}.oi-account-login:before{content:'\e000'}.oi-account-logout:before{content:'\e001'}.oi-action-redo:before{content:'\e002'}.oi-action-undo:before{content:'\e003'}.oi-align-center:before{content:'\e004'}.oi-align-left:before{content:'\e005'}.oi-align-right:before{content:'\e006'}.oi-aperture:before{content:'\e007'}.oi-arrow-bottom:before{content:'\e008'}.oi-arrow-circle-bottom:before{content:'\e009'}.oi-arrow-circle-left:before{content:'\e00a'}.oi-arrow-circle-right:before{content:'\e00b'}.oi-arrow-circle-top:before{content:'\e00c'}.oi-arrow-left:before{content:'\e00d'}.oi-arrow-right:before{content:'\e00e'}.oi-arrow-thick-bottom:before{content:'\e00f'}.oi-arrow-thick-left:before{content:'\e010'}.oi-arrow-thick-right:before{content:'\e011'}.oi-arrow-thick-top:before{content:'\e012'}.oi-arrow-top:before{content:'\e013'}.oi-audio-spectrum:before{content:'\e014'}.oi-audio:before{content:'\e015'}.oi-badge:before{content:'\e016'}.oi-ban:before{content:'\e017'}.oi-bar-chart:before{content:'\e018'}.oi-basket:before{content:'\e019'}.oi-battery-empty:before{content:'\e01a'}.oi-battery-full:before{content:'\e01b'}.oi-beaker:before{content:'\e01c'}.oi-bell:before{content:'\e01d'}.oi-bluetooth:before{content:'\e01e'}.oi-bold:before{content:'\e01f'}.oi-bolt:before{content:'\e020'}.oi-book:before{content:'\e021'}.oi-bookmark:before{content:'\e022'}.oi-box:before{content:'\e023'}.oi-briefcase:before{content:'\e024'}.oi-british-pound:before{content:'\e025'}.oi-browser:before{content:'\e026'}.oi-brush:before{content:'\e027'}.oi-bug:before{content:'\e028'}.oi-bullhorn:before{content:'\e029'}.oi-calculator:before{content:'\e02a'}.oi-calendar:before{content:'\e02b'}.oi-camera-slr:before{content:'\e02c'}.oi-caret-bottom:before{content:'\e02d'}.oi-caret-left:before{content:'\e02e'}.oi-caret-right:before{content:'\e02f'}.oi-caret-top:before{content:'\e030'}.oi-cart:before{content:'\e031'}.oi-chat:before{content:'\e032'}.oi-check:before{content:'\e033'}.oi-chevron-bottom:before{content:'\e034'}.oi-chevron-left:before{content:'\e035'}.oi-chevron-right:before{content:'\e036'}.oi-chevron-top:before{content:'\e037'}.oi-circle-check:before{content:'\e038'}.oi-circle-x:before{content:'\e039'}.oi-clipboard:before{content:'\e03a'}.oi-clock:before{content:'\e03b'}.oi-cloud-download:before{content:'\e03c'}.oi-cloud-upload:before{content:'\e03d'}.oi-cloud:before{content:'\e03e'}.oi-cloudy:before{content:'\e03f'}.oi-code:before{content:'\e040'}.oi-cog:before{content:'\e041'}.oi-collapse-down:before{content:'\e042'}.oi-collapse-left:before{content:'\e043'}.oi-collapse-right:before{content:'\e044'}.oi-collapse-up:before{content:'\e045'}.oi-command:before{content:'\e046'}.oi-comment-square:before{content:'\e047'}.oi-compass:before{content:'\e048'}.oi-contrast:before{content:'\e049'}.oi-copywriting:before{content:'\e04a'}.oi-credit-card:before{content:'\e04b'}.oi-crop:before{content:'\e04c'}.oi-dashboard:before{content:'\e04d'}.oi-data-transfer-download:before{content:'\e04e'}.oi-data-transfer-upload:before{content:'\e04f'}.oi-delete:before{content:'\e050'}.oi-dial:before{content:'\e051'}.oi-document:before{content:'\e052'}.oi-dollar:before{content:'\e053'}.oi-double-quote-sans-left:before{content:'\e054'}.oi-double-quote-sans-right:before{content:'\e055'}.oi-double-quote-serif-left:before{content:'\e056'}.oi-double-quote-serif-right:before{content:'\e057'}.oi-droplet:before{content:'\e058'}.oi-eject:before{content:'\e059'}.oi-elevator:before{content:'\e05a'}.oi-ellipses:before{content:'\e05b'}.oi-envelope-closed:before{content:'\e05c'}.oi-envelope-open:before{content:'\e05d'}.oi-euro:before{content:'\e05e'}.oi-excerpt:before{content:'\e05f'}.oi-expand-down:before{content:'\e060'}.oi-expand-left:before{content:'\e061'}.oi-expand-right:before{content:'\e062'}.oi-expand-up:before{content:'\e063'}.oi-external-link:before{content:'\e064'}.oi-eye:before{content:'\e065'}.oi-eyedropper:before{content:'\e066'}.oi-file:before{content:'\e067'}.oi-fire:before{content:'\e068'}.oi-flag:before{content:'\e069'}.oi-flash:before{content:'\e06a'}.oi-folder:before{content:'\e06b'}.oi-fork:before{content:'\e06c'}.oi-fullscreen-enter:before{content:'\e06d'}.oi-fullscreen-exit:before{content:'\e06e'}.oi-globe:before{content:'\e06f'}.oi-graph:before{content:'\e070'}.oi-grid-four-up:before{content:'\e071'}.oi-grid-three-up:before{content:'\e072'}.oi-grid-two-up:before{content:'\e073'}.oi-hard-drive:before{content:'\e074'}.oi-header:before{content:'\e075'}.oi-headphones:before{content:'\e076'}.oi-heart:before{content:'\e077'}.oi-home:before{content:'\e078'}.oi-image:before{content:'\e079'}.oi-inbox:before{content:'\e07a'}.oi-infinity:before{content:'\e07b'}.oi-info:before{content:'\e07c'}.oi-italic:before{content:'\e07d'}.oi-justify-center:before{content:'\e07e'}.oi-justify-left:before{content:'\e07f'}.oi-justify-right:before{content:'\e080'}.oi-key:before{content:'\e081'}.oi-laptop:before{content:'\e082'}.oi-layers:before{content:'\e083'}.oi-lightbulb:before{content:'\e084'}.oi-link-broken:before{content:'\e085'}.oi-link-intact:before{content:'\e086'}.oi-list-rich:before{content:'\e087'}.oi-list:before{content:'\e088'}.oi-location:before{content:'\e089'}.oi-lock-locked:before{content:'\e08a'}.oi-lock-unlocked:before{content:'\e08b'}.oi-loop-circular:before{content:'\e08c'}.oi-loop-square:before{content:'\e08d'}.oi-loop:before{content:'\e08e'}.oi-magnifying-glass:before{content:'\e08f'}.oi-map-marker:before{content:'\e090'}.oi-map:before{content:'\e091'}.oi-media-pause:before{content:'\e092'}.oi-media-play:before{content:'\e093'}.oi-media-record:before{content:'\e094'}.oi-media-skip-backward:before{content:'\e095'}.oi-media-skip-forward:before{content:'\e096'}.oi-media-step-backward:before{content:'\e097'}.oi-media-step-forward:before{content:'\e098'}.oi-media-stop:before{content:'\e099'}.oi-medical-cross:before{content:'\e09a'}.oi-menu:before{content:'\e09b'}.oi-microphone:before{content:'\e09c'}.oi-minus:before{content:'\e09d'}.oi-monitor:before{content:'\e09e'}.oi-moon:before{content:'\e09f'}.oi-move:before{content:'\e0a0'}.oi-musical-note:before{content:'\e0a1'}.oi-paperclip:before{content:'\e0a2'}.oi-pencil:before{content:'\e0a3'}.oi-people:before{content:'\e0a4'}.oi-person:before{content:'\e0a5'}.oi-phone:before{content:'\e0a6'}.oi-pie-chart:before{content:'\e0a7'}.oi-pin:before{content:'\e0a8'}.oi-play-circle:before{content:'\e0a9'}.oi-plus:before{content:'\e0aa'}.oi-power-standby:before{content:'\e0ab'}.oi-print:before{content:'\e0ac'}.oi-project:before{content:'\e0ad'}.oi-pulse:before{content:'\e0ae'}.oi-puzzle-piece:before{content:'\e0af'}.oi-question-mark:before{content:'\e0b0'}.oi-rain:before{content:'\e0b1'}.oi-random:before{content:'\e0b2'}.oi-reload:before{content:'\e0b3'}.oi-resize-both:before{content:'\e0b4'}.oi-resize-height:before{content:'\e0b5'}.oi-resize-width:before{content:'\e0b6'}.oi-rss-alt:before{content:'\e0b7'}.oi-rss:before{content:'\e0b8'}.oi-script:before{content:'\e0b9'}.oi-share-boxed:before{content:'\e0ba'}.oi-share:before{content:'\e0bb'}.oi-shield:before{content:'\e0bc'}.oi-signal:before{content:'\e0bd'}.oi-signpost:before{content:'\e0be'}.oi-sort-ascending:before{content:'\e0bf'}.oi-sort-descending:before{content:'\e0c0'}.oi-spreadsheet:before{content:'\e0c1'}.oi-star:before{content:'\e0c2'}.oi-sun:before{content:'\e0c3'}.oi-tablet:before{content:'\e0c4'}.oi-tag:before{content:'\e0c5'}.oi-tags:before{content:'\e0c6'}.oi-target:before{content:'\e0c7'}.oi-task:before{content:'\e0c8'}.oi-terminal:before{content:'\e0c9'}.oi-text:before{content:'\e0ca'}.oi-thumb-down:before{content:'\e0cb'}.oi-thumb-up:before{content:'\e0cc'}.oi-timer:before{content:'\e0cd'}.oi-transfer:before{content:'\e0ce'}.oi-trash:before{content:'\e0cf'}.oi-underline:before{content:'\e0d0'}.oi-vertical-align-bottom:before{content:'\e0d1'}.oi-vertical-align-center:before{content:'\e0d2'}.oi-vertical-align-top:before{content:'\e0d3'}.oi-video:before{content:'\e0d4'}.oi-volume-high:before{content:'\e0d5'}.oi-volume-low:before{content:'\e0d6'}.oi-volume-off:before{content:'\e0d7'}.oi-warning:before{content:'\e0d8'}.oi-wifi:before{content:'\e0d9'}.oi-wrench:before{content:'\e0da'}.oi-x:before{content:'\e0db'}.oi-yen:before{content:'\e0dc'}.oi-zoom-in:before{content:'\e0dd'}.oi-zoom-out:before{content:'\e0de'} -------------------------------------------------------------------------------- /ContosoOnline/Store/wwwroot/css/open-iconic/font/fonts/open-iconic.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bradygaster/dotnet-cloud-native-build-2023/7fe51b554794d1becc48305972e66133b6e35c9b/ContosoOnline/Store/wwwroot/css/open-iconic/font/fonts/open-iconic.eot -------------------------------------------------------------------------------- /ContosoOnline/Store/wwwroot/css/open-iconic/font/fonts/open-iconic.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bradygaster/dotnet-cloud-native-build-2023/7fe51b554794d1becc48305972e66133b6e35c9b/ContosoOnline/Store/wwwroot/css/open-iconic/font/fonts/open-iconic.otf -------------------------------------------------------------------------------- /ContosoOnline/Store/wwwroot/css/open-iconic/font/fonts/open-iconic.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | Created by FontForge 20120731 at Tue Jul 1 20:39:22 2014 9 | By P.J. Onori 10 | Created by P.J. Onori with FontForge 2.0 (http://fontforge.sf.net) 11 | 12 | 13 | 14 | 27 | 28 | 30 | 32 | 34 | 36 | 38 | 40 | 42 | 45 | 47 | 49 | 51 | 53 | 55 | 57 | 59 | 61 | 63 | 65 | 67 | 69 | 71 | 74 | 76 | 79 | 81 | 84 | 86 | 88 | 91 | 93 | 95 | 98 | 100 | 102 | 104 | 106 | 109 | 112 | 115 | 117 | 121 | 123 | 125 | 127 | 130 | 132 | 134 | 136 | 138 | 141 | 143 | 145 | 147 | 149 | 151 | 153 | 155 | 157 | 159 | 162 | 165 | 167 | 169 | 172 | 174 | 177 | 179 | 181 | 183 | 185 | 189 | 191 | 194 | 196 | 198 | 200 | 202 | 205 | 207 | 209 | 211 | 213 | 215 | 218 | 220 | 222 | 224 | 226 | 228 | 230 | 232 | 234 | 236 | 238 | 241 | 243 | 245 | 247 | 249 | 251 | 253 | 256 | 259 | 261 | 263 | 265 | 267 | 269 | 272 | 274 | 276 | 280 | 282 | 285 | 287 | 289 | 292 | 295 | 298 | 300 | 302 | 304 | 306 | 309 | 312 | 314 | 316 | 318 | 320 | 322 | 324 | 326 | 330 | 334 | 338 | 340 | 343 | 345 | 347 | 349 | 351 | 353 | 355 | 358 | 360 | 363 | 365 | 367 | 369 | 371 | 373 | 375 | 377 | 379 | 381 | 383 | 386 | 388 | 390 | 392 | 394 | 396 | 399 | 401 | 404 | 406 | 408 | 410 | 412 | 414 | 416 | 419 | 421 | 423 | 425 | 428 | 431 | 435 | 438 | 440 | 442 | 444 | 446 | 448 | 451 | 453 | 455 | 457 | 460 | 462 | 464 | 466 | 468 | 471 | 473 | 477 | 479 | 481 | 483 | 486 | 488 | 490 | 492 | 494 | 496 | 499 | 501 | 504 | 506 | 509 | 512 | 515 | 517 | 520 | 522 | 524 | 526 | 529 | 532 | 534 | 536 | 539 | 542 | 543 | 544 | -------------------------------------------------------------------------------- /ContosoOnline/Store/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bradygaster/dotnet-cloud-native-build-2023/7fe51b554794d1becc48305972e66133b6e35c9b/ContosoOnline/Store/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf -------------------------------------------------------------------------------- /ContosoOnline/Store/wwwroot/css/open-iconic/font/fonts/open-iconic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bradygaster/dotnet-cloud-native-build-2023/7fe51b554794d1becc48305972e66133b6e35c9b/ContosoOnline/Store/wwwroot/css/open-iconic/font/fonts/open-iconic.woff -------------------------------------------------------------------------------- /ContosoOnline/Store/wwwroot/css/site.css: -------------------------------------------------------------------------------- 1 | @import url('open-iconic/font/css/open-iconic-bootstrap.min.css'); 2 | 3 | html, body { 4 | font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; 5 | } 6 | 7 | h1:focus { 8 | outline: none; 9 | } 10 | 11 | a, .btn-link { 12 | color: #0071c1; 13 | } 14 | 15 | .btn-primary { 16 | color: #fff; 17 | background-color: #1b6ec2; 18 | border-color: #1861ac; 19 | } 20 | 21 | .btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus { 22 | box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb; 23 | } 24 | 25 | .content { 26 | padding-top: 1.1rem; 27 | } 28 | 29 | .valid.modified:not([type=checkbox]) { 30 | outline: 1px solid #26b050; 31 | } 32 | 33 | .invalid { 34 | outline: 1px solid red; 35 | } 36 | 37 | .validation-message { 38 | color: red; 39 | } 40 | 41 | #blazor-error-ui { 42 | background: lightyellow; 43 | bottom: 0; 44 | box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); 45 | display: none; 46 | left: 0; 47 | padding: 0.6rem 1.25rem 0.7rem 1.25rem; 48 | position: fixed; 49 | width: 100%; 50 | z-index: 1000; 51 | } 52 | 53 | #blazor-error-ui .dismiss { 54 | cursor: pointer; 55 | position: absolute; 56 | right: 0.75rem; 57 | top: 0.5rem; 58 | } 59 | 60 | .blazor-error-boundary { 61 | background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121; 62 | padding: 1rem 1rem 1rem 3.7rem; 63 | color: white; 64 | } 65 | 66 | .blazor-error-boundary::after { 67 | content: "An error has occurred." 68 | } 69 | -------------------------------------------------------------------------------- /ContosoOnline/Store/wwwroot/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bradygaster/dotnet-cloud-native-build-2023/7fe51b554794d1becc48305972e66133b6e35c9b/ContosoOnline/Store/wwwroot/favicon.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Brady Gaster 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. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | .NET Cloud Native - Build 2023 Session 2 | --- 3 | 4 | In this session, we showed how .NET is great for building cloud-native apps, and we showed some of the upcoming features in .NET 8.0 that will make the process of building cloud-native apps more streamlined, performant, and modern. 5 | 6 | -------------------------------------------------------------------------------- /azure.yaml: -------------------------------------------------------------------------------- 1 | # yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json 2 | 3 | name: ContosoOnline 4 | services: 5 | app: 6 | language: dotnet 7 | project: .\ContosoOnline\ContosoOnline.AppHost\ContosoOnline.AppHost.csproj 8 | host: containerapp 9 | -------------------------------------------------------------------------------- /docs/azd-install-script.md: -------------------------------------------------------------------------------- 1 | 2 | ## Process 3 | 4 | 1. To get a good base down along with my `azd init` command, I include the core files `jongio` (Jon Gallant) wrote to make the getting-started with a new AZD deployment easier. 5 | 6 | ``` 7 | azd init -t jongio/azd-starter-bicep-core 8 | ``` 9 | 10 | 2. CENAS 11 | ``` 12 | curl -fsSL https://aka.ms/install-azd.sh | bash 13 | ``` 14 | 15 | 3. BATATAS 16 | 17 | ``` 18 | cd infra 19 | ``` 20 | 21 | 4. MAIS BATATAS 22 | 23 | ``` 24 | azd auth login 25 | ``` 26 | 27 | 5. AINDA MAIS CENAS 28 | ``` 29 | azd provision --preview 30 | ``` 31 | 32 | ## Install .NET 7 and .NET 8 33 | 34 | 6. AINDA MAIS BATATAS 35 | ``` 36 | azd provision 37 | ``` 38 | 39 | 7. MUITAS CENAS 40 | 41 | ``` 42 | azd up 43 | ``` 44 | 45 | -------------------------------------------------------------------------------- /docs/azd-installation-writeup.md: -------------------------------------------------------------------------------- 1 | # AZD Installation 2 | 3 | This document will outline the entire process I went through to add AZD deployment support to the app. The code is finished, the app works in Docker Compose fine, as well as on localhost. The goal is to develop an AZD deployment template that will push the app out to Azure Container Apps. 4 | 5 | ## Process 6 | 7 | 1. To get a good base down along with my `azd init` command, I include the core files `jongio` (Jon Gallant) wrote to make the getting-started with a new AZD deployment easier. 8 | 9 | ``` 10 | azd init -t jongio/azd-starter-bicep-core 11 | ``` 12 | 13 | 1. Confirm that I'd like to add the AZD files to the existing non-empty directory. 14 | 15 | 1. Accept the `ContosoOnline-dev` nomenclature for the environment name. 16 | 17 | 1. Copy `main.bicep` from another project I have, as the boilerplate for this file is almost identical to what I'll want here for Contoso Online. 18 | 19 | 1. Edit `main.bicep` down to the bare minimum for what the sample app would need to run. 20 | 21 | 1. Write the bicep for each of the services that need to be deployed: 22 | 23 | 1. `proxy.bicep` - the YARP front door 24 | 1. `store.bicep` - the front door 25 | 1. `orders.bicep` - the REST API that receives orders and stores them in PostgreSQL 26 | 1. `products.bicep` - the gRPC service for products 27 | 1. `orderprocessor.bicep` - the microservice that processes incoming orders 28 | 29 | 1. Run `azd provision` a few times to make sure things would provision and fixed bugs. 30 | 31 | 1. Created a new environment, did an `azd up`, and then debugged issues with my bicep and configuration. I knew I'd need to add PostgreSQL at some point since that's a dependency so I knew the first few tries would fail. 32 | 33 | 1. Looked over samples and tweaked mine to match the Postgres implementation in the samples [had to ping a team member to get this]. 34 | 35 | 1. Tried the postgres-inclusive bicep tweaks I'd made with a new deployment. 36 | 37 | 1. Nothing was working. Found the `PRODUCTS_URL` and `ORDERS_URL` configuration properties in the `IOrderProcessor` project and added those to the IAC code. 38 | 39 | 1. Added `envvars` endpoint to the orders API, and wired up Swagger UI for it to make it easier to test. 40 | 41 | 1. Turned off most of the features in the `orders` API to get it to the bare min, then created a new environment and provisioned the `postgres` container app along with the `orders` container app. I ran the Swagger UI I'd just added and took note that the environment variables specific to Postgres have indeed been injected into the `orders` container app. 42 | 43 | 1. Re-enabled the call to `AddDatabase()` in the `orders` project's `Program.cs` file to enable connectivity on startup to the `postgres` container app, then run `azd deploy orders` to re-deploy the app with the connection enabled. The `orders` API is still working, whilst not actually contacting the database since the DB-facing API methods have also been disabled. 44 | 45 | 1. Re-enabled the call to `app.MapOrdersApi()` to turn the API endpoints on. Re-deployed the `orders` container app. The revision failed on start. So, I re-commented the call to `api.MapOrdersApi()` and re-deployed the `orders` container app to see if the new revision would light up. 46 | 47 | 1. Manually write a kusto query to look at the failing revision's logs: 48 | 49 | ContainerAppConsoleLogs_CL 50 | | project ContainerAppName_s, Log_s, TimeGenerated, RevisionName_s 51 | | where RevisionName_s == 'orders--azd-1689262172' 52 | 53 | When the logs returned, it looked like the connection to `postgres` is in fact, failing. I'm confused as to what's gotten me into this state so I'm creating my 6th environment and deleting this one to try this again, starting with provisioning the `postgres` container app before provisioning and deploying the `orders` container app. 54 | 55 | 1. `azd env new` 56 | 1. `azd provision` 57 | 1. `azd deploy postgres` - This actually fails as there's nothing to deploy. 58 | 1. Checked the logs for `postgres` once it came up. 59 | 1. Turn off all `MapOrdersApi`and `AddDatabase` so the `orders` app is bare bones. 60 | 1. Found a connection string in `appsettings.json` that was probably messing me up, deleted that after deploying step-by-step and it seems to work. 61 | 1. Turned `AddDatabase` back on and deployed, the site works. 62 | 1. Turned `MapOrdersApi` back on and deployed. The site works, and I now see all the API methods. 63 | 1. Turned observability back on and deployed. If the `orders` app continues to work, it demonstrates that the other apps will continue to function in the abscence of Prometheus and Zipkin. 64 | 1. The `orders` API is working, still. 65 | 1. `azd deploy products` to deploy the back-end products gRPC service. I get a "Degraded" state on the revision following deployment. Will need to investigate what's happening here. 66 | 1. After debugging with the team members and reviewing `appsettings.json` code and IAC code, I realized there were port conflicts in the locally-running and deployed code so I resolved those and got `products` successfully deploying. 67 | 68 | 69 | ## Things I wish the ACA tools in VS Code would do 70 | 71 | This is a list of things I'm thinking about as I tinker with the extension that I'll take the PM who owns it to pitch some ideas. 72 | 73 | 1. I'd love to have a way of viewing all the environment variables for an individual container app, and I'd like that list to include all the service dependency injections. Everything. All the `envvars`. -------------------------------------------------------------------------------- /docs/env-setup-guide.md: -------------------------------------------------------------------------------- 1 | 2 | ## Process 3 | 4 | 1. To get a good base down along with my `azd init` command, I include the core files `jongio` (Jon Gallant) wrote to make the getting-started with a new AZD deployment easier. 5 | 6 | ``` 7 | azd init -t jongio/azd-starter-bicep-core 8 | ``` 9 | 10 | 2. CENAS 11 | ``` 12 | curl -fsSL https://aka.ms/install-azd.sh | bash 13 | ``` 14 | 15 | 3. BATATAS 16 | 17 | ``` 18 | cd infra 19 | ``` 20 | 21 | 4. MAIS BATATAS 22 | 23 | ``` 24 | azd auth login 25 | ``` 26 | 27 | 5. AINDA MAIS CENAS 28 | ``` 29 | azd provision --preview 30 | ``` 31 | 32 | ## Install .NET 7 and .NET 8 33 | 34 | 6. AINDA MAIS BATATAS 35 | ``` 36 | azd provision 37 | ``` 38 | 39 | 7. MUITAS CENAS 40 | 41 | ``` 42 | azd up 43 | ``` 44 | 45 | 46 | -------------------------------------------------------------------------------- /docs/topology.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bradygaster/dotnet-cloud-native-build-2023/7fe51b554794d1becc48305972e66133b6e35c9b/docs/topology.png --------------------------------------------------------------------------------