Wilson Mar bio photo

Wilson Mar

Hello!

Calendar YouTube Github

LinkedIn

Write C# Azure Functions and cross-platform .NET Core apps within the Microsoft ecosystem

US (English)   Norsk (Norwegian)   Español (Spanish)   Français (French)   Deutsch (German)   Italiano   Português   Estonian   اَلْعَرَبِيَّةُ (Egypt Arabic)   Napali   中文 (简体) Chinese (Simplified)   日本語 Japanese   한국어 Korean

Overview

Microsoft’s C# programming language is used to build a wide array of applicatons:

  • Business applications to capture, analyze, and process data
  • Dynamic web applications that can be accessed from a web browser
  • Games, both 2D and 3D
  • Financial and scientific applications
  • Cloud-based applications
  • Mobile applications

NOTE: Content here are my personal opinions, and not intended to represent any employer (past or present). “PROTIP:” here highlight information I haven’t seen elsewhere on the internet because it is hard-won, little-know but significant facts based on my personal research and experience.

https://dotnet.microsoft.com/en-us/learn/dotnet/what-is-dotnet

https://dotnet.microsoft.com/en-us/download

Build a complete stack now

Anyone with an Azure account and internet access can create a production-worthy, scalable and resilient enterprise stack, thanks to Infrastructure as Code (HashiCorp Terraform templates) and other automation.

Let’s first install so concepts can be shown practically.

Blazor is not just for building websites; it can also be used to create hybrid mobile and desktop apps when combined with .NET MAUI.


All the pieces

Job descriptions for a “Microsoft full stack developer” mention dozens of technologies. Here is the order to make sense of them:

  1. .NET is the ecosystem Microsoft built (beginning in 2002) around an architecture similar to Java, where
  2. CIL (Microsoft Intermediate Language, aka “bytecode”) is created from compiling source code written in various human-readable programming languages (C#, Visual Basic). MSIL is read by Microsoft’s proprietary
  3. CLR (Common Language Runtime), which is equivalent to the JVM (Java Virtual Machine) that turn bytecode into native code executed by specific computer processors (x86, ARM, etc.).

    In theory, this is instead of distributing different executable files for different platforms and CPU types. However, …

    .NET Core can be deployed side by side with an app so that it can change frequently, knowing those changes will not affect other .NET Core apps on the same machine.

  4. .NET 8, also known as “Modern .NET”, unifies legacy platforms and standards”https://github.com/markjprice/cs12dotnet8/blob/main/docs/ch01-dotnet-history.md combines and thus replaces:
    • “.NET Framework” which only ran on Windows, now “feature complete” April 18, 2019 and thus no longer being developed by Microsoft.
    • “.NET Core” which was rebuilt to be faster and cross-platform (on Linux, Mac, Windows) with modularity to provide flexible deployment. Last release December 3, 2019. .NET Core SDK (Software Development Kit) are libraries referenced by several programming languages
    • .NET Standard (“netstandard”) library
    • ASP.NET Core is for web development using the MVC (Model-View-Controller) programming pattern (equivalent to Node.Js)
    • Xamarin built from Mono open-sourced outside Microsoft (purchased 2016), subsequently adopted by the Unity game engine

  5. Nuget is the repository of .NET packages online (equivalent to NPM, Maven, PyPi, etc.)
  6. Visual Studio Code is the free text editor (with lots of add-ons)
    • Visual Studio 2022 for Windows is the licen$ed editor with powerful debugging features (runs only on Windows machines)
    • JetBrains Rider is used by many developers, especially those using Mac and Linux. Has ReSharper and other utilities.

  7. VSCode extensions:
    • C# (C-sharp)
    • F# (F-sharp) is the functional programming language
  8. PowerShell CLI (equivalent to Bash Shell on Linux)

  9. .NET MAUI to build apps running on iPhone and Android mobile devices
  10. Razor provides templating in code (equivalent to handle bars)
  11. Blazor to build user interface components run in internet browsers WebAssembly for near-native performance [course]
  12. Silverlight deprecated?
  13. EF Core (Enterprise Framework)
  14. SignalR to code real-time RPC (Remote Procedure Calls) using HTTP/2 protocol
  15. Xamarin/Mono is .NET for mobile. It’s being replaced by .NET MAUI.
  16. UWP (Universal Windows Platform) is used to build desktop apps that run on Windows, Mac, and Linux
  17. gRPC in ASP.NET Core to develop contract-first, high-performance web services
  18. More granular than RBAC is ASP.NET Core Identity Roles, which supports CBAC (Claims-Based Access Control) enforced through Authorization Policy stored in the AspNetUserClaims table.*

  19. Dapr (Distributed Application Runtime) apps are cloud-native event-driven, portable runtimes that can run within Kubernetes on most clouds

  20. MS-SQL is the database from Microsoft that runs on many platforms.
  21. Azure Cosmos DB runs across regions in the Azure cloud
  22. LINQ is Microsoft’s proprietary extension to the SQL language for querying and manipulating data within relational (SQL) databases.
  23. EF (Enterprise Framework) Core enables object-to-data store mapping when programming reading and writing to relational data stores (such as SQLite and SQL Server).



Additionally, there are DevOps and “Backing” utilities created and managed by a platform team for developers to consume:

  • IAM for MFA and SSO
  • Secrets management (HashiCorp Vault)
  • Network management (Load Balancers, Gateways)
  • Git and GitHub
  • CI/CD
  • Code vulnerability scanners (SonarQube, etc.)

  • Log accumulation, visualization of trends, and alerting
  • Backup and restore
  • Kubernetes and Istio Service Mesh
  • Health checks
  • Monitoring and Observability
  • etc.


About .NET Core

.NET is open-sourced through a .NET Foundation under the MIT license, which has almost no restrictions. Users can make money off it.

https://dotnet.microsoft.com/en-us/learn/dotnet/architecture-guides

VSCode Keyboard Shortcuts

PROTIP: Download a PDF of keyboard shortcuts for your operating system:

  • Windows: https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf
  • macOS: https://code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf
  • Linux: https://code.visualstudio.com/shortcuts/keyboard-shortcuts-linux.pdf

To customize your keyboard shortcuts for Visual Studio Code” see https://code.visualstudio.com/docs/getstarted/keybindings.

To see a list of templates:

dotnet new list
Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry
 
----------------
Installed an ASP.NET Core HTTPS development certificate.
To trust the certificate, run 'dotnet dev-certs https --trust'
Learn about HTTPS: https://aka.ms/dotnet-https
 
----------------
Write your first app: https://aka.ms/dotnet-hello-world
Find out what's new: https://aka.ms/dotnet-whats-new
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli
--------------------------------------------------------------------------------------
An issue was encountered verifying workloads. For more information, run "dotnet workload update".
These templates matched your input: 
 
Template Name                                 Short Name                  Language    Tags                            
--------------------------------------------  --------------------------  ----------  --------------------------------
API Controller                                apicontroller               [C#]        Web/ASP.NET                     
ASP.NET Core Empty                            web                         [C#],F#     Web/Empty                       
ASP.NET Core gRPC Service                     grpc                        [C#]        Web/gRPC/API/Service            
ASP.NET Core Web API                          webapi                      [C#],F#     Web/WebAPI/Web API/API/Service  
ASP.NET Core Web API (native AOT)             webapiaot                   [C#]        Web/Web API/API/Service         
ASP.NET Core Web App (Model-View-Controller)  mvc                         [C#],F#     Web/MVC                         
ASP.NET Core Web App (Razor Pages)            webapp,razor                [C#]        Web/MVC/Razor Pages             
ASP.NET Core with Angular                     angular                     [C#]        Web/MVC/SPA                     
ASP.NET Core with React.js                    react                       [C#]        Web/MVC/SPA                     
Blazor Server App                             blazorserver                [C#]        Web/Blazor                      
Blazor Server App Empty                       blazorserver-empty          [C#]        Web/Blazor/Empty                
Blazor Web App                                blazor                      [C#]        Web/Blazor/WebAssembly          
Blazor WebAssembly App Empty                  blazorwasm-empty            [C#]        Web/Blazor/WebAssembly/PWA/Empty
Blazor WebAssembly Standalone App             blazorwasm                  [C#]        Web/Blazor/WebAssembly/PWA      
Class Library                                 classlib                    [C#],F#,VB  Common/Library                  
Console App                                   console                     [C#],F#,VB  Common/Console                  
dotnet gitignore file                         gitignore,.gitignore                    Config                          
Dotnet local tool manifest file               tool-manifest                           Config                          
EditorConfig file                             editorconfig,.editorconfig              Config                          
global.json file                              globaljson,global.json                  Config                          
MSBuild Directory.Build.props file            buildprops                              MSBuild/props                   
MSBuild Directory.Build.targets file          buildtargets                            MSBuild/props                   
MSTest Playwright Test Project                mstest-playwright           [C#]        Test/MSTest/Playwright          
MSTest Test Project                           mstest                      [C#],F#,VB  Test/MSTest                     
MVC Controller                                mvccontroller               [C#]        Web/ASP.NET                     
MVC ViewImports                               viewimports                 [C#]        Web/ASP.NET                     
MVC ViewStart                                 viewstart                   [C#]        Web/ASP.NET                     
NuGet Config                                  nugetconfig,nuget.config                Config                          
NUnit 3 Test Item                             nunit-test                  [C#],F#,VB  Test/NUnit                      
NUnit 3 Test Project                          nunit                       [C#],F#,VB  Test/NUnit                      
NUnit Playwright Test Project                 nunit-playwright            [C#]        Test/NUnit/Playwright           
Protocol Buffer File                          proto                                   Web/gRPC                        
Razor Class Library                           razorclasslib               [C#]        Web/Razor/Library               
Razor Component                               razorcomponent              [C#]        Web/ASP.NET                     
Razor Page                                    page                        [C#]        Web/ASP.NET                     
Razor View                                    view                        [C#]        Web/ASP.NET                     
Solution File                                 sln,solution                            Solution                        
Web Config                                    webconfig                               Config                          
Worker Service                                worker                      [C#],F#     Common/Worker/Web               
xUnit Test Project                            xunit                       [C#],F#,VB  Test/xUnit                      
   

To get Vue templates,

  1. start a browser and navigate to https://www.nuget.org/packages.
  2. Enter vue in the Search for packages… textbox

    note that about 210 packages are returned.

    dotnet new --install "Vue.Simple.Template"
    dotnet new simplevue
    

A. Build using a Mac laptop

https://www.youtube.com/watch?v=bEfBfBQq7EE

  1. Open a Terminal on your Mac
  2. Install MacOS utilities for development (Docker desktop, etc.)
  3. Install VSCode
  4. Install azure-cli
  5. Install dotnet (.NET Core) CLI
  6. Use dotnet info CLI command

  7. Install dotnet-sdk

    ==> Downloading https://download.visualstudio.microsoft.com/download/pr/dfbffbab
    ######################################################################## 100.0%
    ==> Installing Cask dotnet-sdk
    ==> Running installer for dotnet-sdk; your password may be necessary.
    Package installers may write to any location; options such as `--appdir` are ignored.
    Password:
    installer: Package name is Microsoft .NET SDK 7.0.102 (arm64)
    installer: Upgrading at base path /
    installer: The upgrade was successful.
    ==> Linking Binary 'dotnet' to '/opt/homebrew/bin/dotnet'
    🍺  dotnet-sdk was successfully installed!
    
  8. Install brew install protobuf ; protoc –version # libprotoc 3.21.12
  9. Install npm

  10. Install eShopOnContainers

    https://github.com/dotnet-architecture/eShopOnContainers/wiki/Mac-setup

dotnet info CLI commands

Regardless of what environment:

  1. Get environment metadata:

    dotnet --info

    REMEMBER: Different version of .NET can run side-by-side within the same server.

    .NET Release Schedule

    Microsoft has planned the versioning and dates of .NET releases years in advance, for a cadence of one a year:

    dotnet-versions-1154x227.jpg

    • “LTS” (Long Term Support) releases are even numbered.
    • “STS” (Standard Term Support) releases (previously “Current” releases) are supported only 6 months.

    https://dotnet.microsoft.com/en-us/platform/support/policy/dotnet-core#cadence

  2. List specific dates for release availability and End of support (End of life).

    https://dotnet.microsoft.com/download/dotnet.core

ASP.NET Core

ASP.NET Core is a complete rewrite of the previous ASP.NET framework.

ASP.NET Core is used for developing cloud-based such as web applications, mobile applications, and IoT applications.

  1. S

    dotnet new

Cloud Native

“Beyond the 12 Factor App: Exploring the DNA of Highly Scalable, Resilient Cloud Applications” by Kevin Hoffman adds 3 more to the 12 Factor App published in 2011:

  1. One codebase, one application
  2. API first
  3. Dependency management
  4. Design, build, release, and run
  5. Configuration, credentials, and code
  6. Logs
  7. Disposability
  8. Backing services
  9. Environment parity
  10. Administrative processes
  11. Port binding
  12. Stateless processes

  13. Concurrency
  14. Telemetry
  15. Authentication and authorization

eShopOnContainers

  • http://aka.ms/MicroservicesArchitecture redirects to
    https://github.com/dotnet-architecture/eShopOnContainers
  • https://go.particular.net/eShopOnContainers open-sourced at https://github.com/Particular using NServiceBus
  • https://codeopinion.com/eshoponcontainers-a-microservice-based-net-core-sample-application/
  • https://www.neolisk.blog/posts/2021-06-05-dotnet-arch-eshop-on-cont/

eShopOnContainers is a sample microservices and container-based application that is cross-platform (runs on Linux Windows and macOS) that began in 2017 by Cesar De la Torre. Now powered by .NET 6, Docker Containers, and Azure Kubernetes Services. Most code editors can be used (Visual Studio, VS for Mac, and CLI based environments with Docker CLI, dotnet CLI, VS Code, etc.).

It’s used as the reference app for PDF: Architecting Cloud-Native .NET Apps for Azure by Robert Vettor and Steve “ardalis” Smith. eshoponcontainers-ui-1411x1078.jpg from https://learn.microsoft.com/en-us/dotnet/architecture/cloud-native/introduce-eshoponcontainers-reference-app

References:

  • eShopOnContainers: https://github.com/dotnet-architecture/eShopOnContainers
  • eShopModernizing: https://github.com/dotnet-architecture/eShopModernizing
  • eShopOnWeb: https://github.com/dotnet-architecture/eShopOnWeb
  • eShopUWP: https://github.com/dotnet-architecture/eShopOnUWP
  • eShopOnContainersAI: https://github.com/dotnet-architecture/eShopOnContainersAI

https://dot.net/architecture redirects to
https://dotnet.microsoft.com/en-us/learn/dotnet/architecture-guides

  1. View online https://github.com/dotnet-architecture/eShopOnContainers
  2. Fork it to your own account – Copy just the dev branch.

  3. Define your GitHub username as a variable in your ~/.bash_profile (replacing “wilsonmar” below with the account name you’re using):

    export GITHUBUSER=”wilsonmar”

    PROTIP: Cloning repos into a folder associated with your GitHub account enables you to differentiate among different GitHub accounts, which require different SSH keys.

  4. On your laptop, in Terminal CLI, create a folder with that name and cd to it:

    cd ; mkdir "$GIBHUBNAME" ; cd "$GIBHUBNAME"
    git clone "git@github.com:$GITHUBUSER/eShopOnContainers.git"
    cd eShopOnContainers/src
    

  5. Invoke Docker Desktop app, then:

    docker-compose build
    

    Note the default values provided so you don’t have to do customizations. But for security, note those that should be customized.

    WARN[0000] The "ESHOP_SERVICE_BUS_USERNAME" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ESHOP_SERVICE_BUS_PASSWORD" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "INSTRUMENTATION_KEY" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ORCHESTRATOR_TYPE" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "INSTRUMENTATION_KEY" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ORCHESTRATOR_TYPE" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ESHOP_SERVICE_BUS_USERNAME" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ESHOP_SERVICE_BUS_PASSWORD" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "INSTRUMENTATION_KEY" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ORCHESTRATOR_TYPE" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ESHOP_SERVICE_BUS_USERNAME" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ESHOP_SERVICE_BUS_PASSWORD" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "INSTRUMENTATION_KEY" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ORCHESTRATOR_TYPE" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "INSTRUMENTATION_KEY" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ORCHESTRATOR_TYPE" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ESHOP_SERVICE_BUS_USERNAME" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ESHOP_SERVICE_BUS_PASSWORD" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "INSTRUMENTATION_KEY" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ORCHESTRATOR_TYPE" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ESHOP_SERVICE_BUS_USERNAME" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ESHOP_SERVICE_BUS_PASSWORD" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "INSTRUMENTATION_KEY" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ORCHESTRATOR_TYPE" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "INSTRUMENTATION_KEY" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ORCHESTRATOR_TYPE" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ESHOP_SERVICE_BUS_USERNAME" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ESHOP_SERVICE_BUS_PASSWORD" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "INSTRUMENTATION_KEY" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ORCHESTRATOR_TYPE" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ESHOP_SERVICE_BUS_USERNAME" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ESHOP_SERVICE_BUS_PASSWORD" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ESHOP_AZURE_STORAGE_CATALOG_NAME" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ESHOP_AZURE_STORAGE_CATALOG_KEY" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "INSTRUMENTATION_KEY" variable is not set. Defaulting to a blank string. 
    WARN[0000] The "ORCHESTRATOR_TYPE" variable is not set. Defaulting to a blank string. 
    [
    

    CAUTION: Here are the errors I’m getting on my ARM mac:

    => [eshop/webmvc:linux-latest build 38/39] WORKDIR /src/Web/WebMVC                                                                       0.4s
     => CANCELED [eshop/payment.api:linux-latest build 39/39] RUN dotnet publish --no-restore -c Release -o /app                             61.6s
     => CANCELED [eshop/catalog.api:linux-latest build 39/39] RUN dotnet publish --no-restore -c Release -o /app                             61.8s
     => ERROR [eshop/mobileshoppingagg:linux-latest build 39/39] RUN dotnet publish --no-restore -c Release -o /app                          59.1s
     => CANCELED [eshop/webhooks.api:linux-latest build 39/39] RUN dotnet publish --no-restore -c Release -o /app                            61.7s
     => CANCELED [eshop/ordering.api:linux-latest build 39/39] RUN dotnet publish --no-restore -c Release -o /app                            61.6s
     => CANCELED [eshop/ordering.backgroundtasks:linux-latest build 39/39] RUN dotnet publish --no-restore -c Release -o /app                61.5s
     => CANCELED [eshop/webmvc:linux-latest build 39/39] RUN dotnet publish --no-restore -c Release -o /app                                  60.6s
     => CANCELED [eshop/basket.api:linux-latest build 39/39] RUN dotnet publish --no-restore -c Release -o /app                              61.4s
     => CANCELED [eshop/identity.api:linux-latest build 39/39] RUN dotnet publish --no-restore -c Release -o /app                            61.6s
     => ERROR [eshop/webshoppingagg:linux-latest build 39/39] RUN dotnet publish --no-restore -c Release -o /app                             58.9s
     => CANCELED [eshop/ordering.signalrhub:linux-latest build 39/39] RUN dotnet publish --no-restore -c Release -o /app                     61.1s
     => CANCELED [eshop/webhooks.client:linux-latest build 39/39] RUN dotnet publish --no-restore -c Release -o /app                         61.4s
    ------
     > [eshop/mobileshoppingagg:linux-latest build 39/39] RUN dotnet publish --no-restore -c Release -o /app:
    #0 1.850 MSBuild version 17.3.2+561848881 for .NET
    #0 52.97   Devspaces.Support -> /src/BuildingBlocks/Devspaces.Support/bin/Release/net6.0/Devspaces.Support.dll
    #0 56.36 /root/.nuget/packages/grpc.tools/2.34.0/build/_protobuf/Google.Protobuf.Tools.targets(84,5): error : Google.Protobuf.Tools cannot determine host OS and CPU. [/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Mobile.Shopping.HttpAggregator.csproj]
    #0 56.36 /root/.nuget/packages/grpc.tools/2.34.0/build/_protobuf/Google.Protobuf.Tools.targets(84,5): error : Use environment variables PROTOBUF_TOOLS_OS={linux|macosx|windows} and PROTOBUF_TOOLS_CPU={x86|x64} to try the closest match to your system. [/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Mobile.Shopping.HttpAggregator.csproj]
    #0 56.36 /root/.nuget/packages/grpc.tools/2.34.0/build/_protobuf/Google.Protobuf.Tools.targets(84,5): error : You may also set PROTOBUF_PROTOC to specify full path to the host-provided compiler (v3.5+ is required). [/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Mobile.Shopping.HttpAggregator.csproj]
    ------
    ------
     > [eshop/webshoppingagg:linux-latest build 39/39] RUN dotnet publish --no-restore -c Release -o /app:
    #0 1.703 MSBuild version 17.3.2+561848881 for .NET
    #0 53.54   Devspaces.Support -> /src/BuildingBlocks/Devspaces.Support/bin/Release/net6.0/Devspaces.Support.dll
    #0 56.63 /root/.nuget/packages/grpc.tools/2.34.0/build/_protobuf/Google.Protobuf.Tools.targets(84,5): error : Google.Protobuf.Tools cannot determine host OS and CPU. [/src/ApiGateways/Web.Bff.Shopping/aggregator/Web.Shopping.HttpAggregator.csproj]
    #0 56.63 /root/.nuget/packages/grpc.tools/2.34.0/build/_protobuf/Google.Protobuf.Tools.targets(84,5): error : Use environment variables PROTOBUF_TOOLS_OS={linux|macosx|windows} and PROTOBUF_TOOLS_CPU={x86|x64} to try the closest match to your system. [/src/ApiGateways/Web.Bff.Shopping/aggregator/Web.Shopping.HttpAggregator.csproj]
    #0 56.63 /root/.nuget/packages/grpc.tools/2.34.0/build/_protobuf/Google.Protobuf.Tools.targets(84,5): error : You may also set PROTOBUF_PROTOC to specify full path to the host-provided compiler (v3.5+ is required). [/src/ApiGateways/Web.Bff.Shopping/aggregator/Web.Shopping.HttpAggregator.csproj]
    ------
    failed to solve: executor failed running [/bin/sh -c dotnet publish --no-restore -c Release -o /app]: exit code: 1
    

    https://danielstoyanoff.medium.com/apple-silicon-docker-dotnet-grpc-is-that-compatible-8a05f1a71d89

  6. When no errors are returned, run the service:

    docker-compose up
    
  7. Pop up browser window for each component:

TODO: More ?

https://gayanf.medium.com/deploy-eshoponcontainers-to-aks-357ac48cda60 Deploy eshopOnContainers to AKS

https://faun.pub/eshoponcontainers-experiment-with-image-scanning-21b73ac5c4b7 eShopOnContainers experiment with image scanning using Trivey. by editing the .github/workflows/basket-api.yml file from the eShopOnContainers repository and add a step between the build and push step.


Rock Stars

Useful websites to code using the Microsoft stack:

  • https://github.com/markjprice/cs11dotnet7
  • https://github.com/markjprice/apps-services-net7

From Mark J. Price: “C# 11 and .NET 7 – Modern Cross-Platform Development Fundamentals: Start building websites and services with ASP.NET Core 7, Blazor, and EF Core 7, 7th Edition” published Nov 2022 by Packt.


C#

C# debuted by Microsoft in 2001 to compete with Java.

C# developers use Microsoft’s Visual Studio IDE (Integrated Development Environment) on Windows.

  • Visual Studio for Mac was crap and is being replaced by Visual Studio Code.
  • Visual Studio Code is a free text editor that runs on Windows, Mac, and Linux.
  • JetBrains Rider is an alternative IDE that runs on Windows, Mac, and Linux, to provide ReSharper and other utilities.

YouTube: Every single feature of C# in 10 minutes

  • Like JavaScript, has curly brackets enclose the body in each function.
  • Like JavaScript, semicolons finish each statement.
  • // precede comments

  • JIT Compiled to IL (Intermediate Language)
  • Rewritten in 2014 .NET Core to run on Linux & Mac.
  • use ASP.NET Core to build web apps on browsers coding Razor, Blazor for native WebAssembly on browsers, with constant connection with server via SignalR
  • Build Unity 2D/3D games

  • C# is a statically-typed language, which means your code will be checked for errors before it gets built into an app.
  • C# is a strongly-typed language, but var has the compiler infer the type implicitly.
  • Compound assignment operators Increment: value++; value += 5; – *=

    Console.WriteLine($"Second: {value++}");  # adds line break
     Console.WriteLine(5 / 10);  # no line break. result = 0 as integer
     int result = 3 + 1 * 5 / 2;  # follows PEMDAS for =5
     
  • class (object) can have 5 access modifiers” public, private, protected, public abstract (for inheriting), public interface (defines what methods class needs)

  • struct defines datatype
  • Functions:
  • Collections:

    using System Collections;  # namespace at top of file
     var myList = new List<string>();
     var myDictionary = new Dictionary<int, int>();
     var myQueue = new Queue<string>();
     var myArray = new int[] { 1, 2, 3 };
     var result = myArray.Select(x => x * 10)    # no semicolon here
                         .Aggregate(0, (acc, cur) => acc + cur * 2);
     
     class MyEnumerable : IEnumerable {
       private readonly string[] _data = new string[] { "one", "two", "three" };
       public IEnumerator GetEnumerator() {
         return _data.GetEnumerator();
       }
     
  • Arrays:

    var myArray = new string[5];
     
  • switch statements can be written without case statements

    string MyFunctionA(int value) ==>
     value switch {
        1 => "one",
        2 => "two",
        > 10 => "large number",
        _ => "unknown"  # naming convention
     };
  • Two ways to do Asynchronous programming:

    async Task MyFunctionB() {
        await Task.Delay(1000);
        Console.WriteLine("Hello");
     }
    void DoAsyncDB() {
        Task.Run(() => startSomthing());
     }
  • Generics with restrictions

    class MyGenericClass<T>() where T : IThing {
        return typeof(T).GetType().Name;
        }
     
  • Record types

  • Patterns:

C# Certifications

Since June, 2022, Microsoft abandoned their 98-xxx series of exams about programming languages.

https://www.freecodecamp.org/learn/foundational-c-sharp-with-microsoft Foundational C# with Microsoft text-based course on Microsoft’s LEARN platform and certification on FreeCodeCamp.dev by Gavin Lon Announced Aug 28, 2023. The challenge concluded in Oct 28, 2023.

Secure C# coding:

  • https://learn.microsoft.com/en-us/dotnet/standard/security/secure-coding-guidelines
  • https://www.c-sharpcorner.com/article/writing-secure-code-using-C-Sharp/
  • https://niccs.cisa.gov/education-training/catalog/sans-institute/secure-coding-net-developing-defensible-applications
  • https://dev.to/bytehide/increase-the-security-of-your-net-applications-5-tips-to-follow-right-now-3888
  • VIDEO: How to secure your Blazor C# API w/ Azure Static Web Apps by Frank Boucher
  • https://www.youtube.com/watch?v=bEfBfBQq7EE&t=14m

Classes on Secure C# Coding:

Pluralsight has “SkillsIQ” tests in:

Steve (@ardalis) Smith’s (of WeeklyTestTips podcast and Clean Architecture) C# Console insurance rating app shows Object Programming SOLID Principles for C# Developers:

  1. Single Responsibility Principle (SIP) - Cohesion & Coupling - delegate details to utility classes (logging) - small cohesive types
  2. Interface Segregation Principle (ISP) - not depend on what’s not needed - use Adaptor for different Context
  3. Open for behavior extensions but Closed for modification Principle (OCP) - Parameters, Inheritance, Composition/Injection - Add functionality by adding more classes
  4. Liskov Substitution Principle (LSP) - subtypes must be substitutable for their base types - subtypes must be fully implemented
  5. Dependency Inversion Principle (DIP) - Details depend on Interfaces & Abstract base classes - prefer Constructor Injection (Explicit Dependencies), Inversion of Control/Dependency Injection containers - Change behavior by passing in different dependencies

W3Schools:

  • W3Shools has a $45 to pass 75% of 50-question in 50 minutes.

LinkedIn Learning:

Jesse Liberty.com:

Microservices architecture e-book (PDF) Domain Driven Design Patterns:

  • Domain Models (Aggregates, Entity, VO, etc.)
  • Simplified CQRS (Command Query Responsibility Segregation):
    • Dapper MicroORM for queries
    • Commands and Mediator pattern
  • Domain Events within the same microservice
  • Integration Events (across microservices)
  • Multi-container docker-compose.yml
  • Swagger w/Swashbuckle
  • Security (Authentication/Authorization) with tokens from IdentityServer4 wrapping ASP.NET Identity

Pluralsign: Building Microservices 29 Jun 2021 by Mark Heath

https://dzfweb.gitbooks.io/microsoft-microservices-book/content/multi-container-microservice-net-applications/microservice-application-design.html


NUnit Testing

xUnit.net is a free, open source, community-focused unit testing tool for the .NET Framework. Written by the original inventor of NUnit v2, xUnit.net is the latest technology for unit testing C#, F#, VB.NET and other .NET languages. xUnit.net works with ReSharper, CodeRush, TestDriven.NET, and Xamarin.

https://www.codeproject.com/Articles/1278829/Angular-7-with-NET-Core-2-2-Global-Weather-Part-3 Now I show you how to create xUnit test project for ASP .NET Core. In Solution Explorer, add new project, Weather.Test.

Code Vulnerability Scan

VIDEO: “Continuous Integration: Live Static Analysis using Visual Studio & the Roslyn API”</a>

The .NET Compiler Platform (“Roslyn API”) was first described in 2014 by Alex Turner in https://msdn.microsoft.com/en-us/magazine/dn879356.aspx https://learn.microsoft.com/en-us/archive/msdn-magazine/2014/special-issue/csharp-and-visual-basic-use-roslyn-to-write-a-live-code-analyzer-for-your-api

News: Keep Up!

https://aka.ms/MicroservicesEbook NET-Microservices-Architecture-for-Containerized-NET-Applications-(Microsoft-eBook).pdf

https://github.com/dotnet-architecture/eShopOnWeb

https://github.com/dotnet-architecture/eShopOnContainers https://aka.ms/microservicesarchitecture

This reference application is meant to support the free

https://github.com/dotnet-architecture/eShopOnWeb/wiki/Getting-Started-for-Beginners .PDF download ebook: Architecting Modern Web Applications with ASP.NET Core and Azure also https://docs.microsoft.com/en-us/dotnet/architecture/modern-web-apps-azure/index

Installing Visual Studio 2019
Creating an ASP.NET Core Web App
Working with data using EF Core
Exposing a Web API
Deploying and hosting the app in Azure

https://dotnet.microsoft.com/download/thank-you/aspnet-ebook Architecting Modern Web Applications with ASP.NET Core and Azure.pdf by Steve “ardalis” Smith

Secrets

  • https://wilsonmar.github.io/hello-vault
  • https://github.com/hashicorp/hello-vault-dotnet

Shared libraries

PROTIP: Use Program.cs NWebSec middlware code library for secure HTTP Header handling. See https://docs.nwebsec.com/en/latest

BOOK: Writing Secure Code in ASP.NET by Cyber Academy

COURSE: ASP.NET: Security on LinkedIn Learning by Christian Wenz shows OWASP10 security vulnerabilities, common attacks, and remediation examples in his known-bad e-commerce app written in ASP.NET.” Packt Publishing December 2023, 798 pages references https://github.com/markjprice/apps-services-net8 and https://static.packt-cdn.com/downloads/9781837637133_ColorImages.pdf


Resources

https://www.youtube.com/dotnet

BOOK: Apps and Services with .NET 8 - Second Edition By Mark J. Price

https://learn-monogame.github.io/how-to/develop-vscode/


More about Azure

This is one of a series about Azure cloud: