Docker Compose:
docker compose upWarning: the default configuration is configured for local non-containerized use.
- Tweak the SSL settings in appsettings.json if required. (
https->http)- Adding
RUN dotnet dev-certs httpshere will automatically generate and associate a Dev SSL cert usable from within the Container.
- Adding
- Comment out Line 14 in - .NET Console input within a Docker Container will error out.
- It can be run by Exec'ing into the Docker Container thereafter (and uncommenting out that line).
Visual Studio Code:
- Install the C# Dev Kit
- Install .NET 9.0 SDK
dotnet new mvc --language "C#"
dotnet run- Autogenerate most boiler-plate using dotnet new console --language "C#".
- C# 13+ examples.
Refresh for ASP.NET 9.0.3
Much easier now to launch a basic app!
- Autogenerate most boiler-plate using dotnet new mvc --language "C#".
- Port binding can be set in appsettings.json
Urls."Urls": "https://0.0.0.0:5177"- Should bind to
localhost. - Can view at: https://localhost:5177
- SSL can be set there too using:
dotnet dev-certs httpswithin the same Docker Image.
- Controllers automatically append their Handler names as subpaths (quite handy).
- Controllers using IActionResult and the relevant helper method (
Ok(),NotFound(), etc.) will automatically serialize data into JSON. - https://medium.com/@nwonahr/working-with-json-data-in-asp-net-core-web-api-fbc4f0ee39c4
Views and Endpoints:
- Simple String/Text Response -> https://localhost:5177/Example/SimpleString
- Automatic JSON Serialization -> https://localhost:5177/Example/JsonResponse
- Default Home -> https://localhost:5177/
- Prebuilt Context Path Example -> https://localhost:5177/Home/Privacy
- Asynchronous SQL Response -> https://localhost:5177/Example/SqlExamples
- Changes to Connection String require
TrustServerCertificate=TrueorEncrypt=Falsefor basic Docker dev testing.
Exercise in PowerShell and MSSQL admin.
- To execute commands within the Container appears to require using Windows PowerShell:
docker exec -u root -it <MY_CONTAINER_ID> "bash"- If you Exec in through Docker Desktop the default user is set to
mssqlnotrootand you won't have permission to execute:/opt/mssql-tools18/bin/sqlcmd - If you attempt to Exec in through Bash (in a new Terminal aside from Docker Desktop), the following error will appear:
the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'from using Bash on a Windows machine (apparently). - Run the following command from a new Windows PowerShell Terminal instead:
/opt/mssql-tools18/bin/sqlcmd -U sa -P FD83wr9DF_*9pke89 -S localhost -Noas described here. (The-Noflag bypasses local HTTPS auth.)
- If you Exec in through Docker Desktop the default user is set to
docker-entrypoint-initdb.disn't supported within the Docker Container but I've kept the convention for familiarity's sake.- Execute:
/opt/mssql-tools18/bin/sqlcmd -U sa -P FD83wr9DF_*9pke89 -S localhost -No -i docker-entrypoint-initdb.d/init_sql.sqlto run the initial scripts. - Since initialization doesn't happen immediately, I've added
sleep 120to the Bash script.
- Execute:
https://learn.microsoft.com/en-us/sql/sql-server/?view=sql-server-ver16
- https://code.visualstudio.com/docs/csharp/get-started
- https://hub.docker.com/r/microsoft/dotnet
- https://hub.docker.com/r/microsoft/mssql-server
- https://medium.com/@dilanlakshitha194/understanding-iactionresult-in-net-core-simplifying-http-response-handling-1e406e22dbcc
- https://learn.microsoft.com/en-us/aspnet/core/web-api/advanced/formatting?view=aspnetcore-9.0
- https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-new
- https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/equality-comparisons
- https://learn.microsoft.com/en-us/dotnet/standard/exceptions/exception-class-and-properties
- https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/events/
- https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties
- https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/delegates/
- https://dev.to/waelhabbal/the-right-way-to-check-for-null-in-c-6gf
- https://github.com/ggagnaux/CSharp-Publisher-Subscriber-Demo/blob/master/PublisherSubscriberDemo/Publisher.cs
- https://learn.microsoft.com/en-us/sql/sql-server/?view=sql-server-ver16
- https://learn.microsoft.com/en-us/ef/core/
- https://github.com/grpm98/pisofinderapi/blob/f114d5860c60267a05ccfd8ed41c162ce8e51224/Data/PisoFinderContext.cs
- https://github.com/adamajammary/simple-web-app-mvc-dotnet/blob/master/SimpleWebAppMVC/Controllers/TasksApiController.cs
- https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-7.0/breaking-changes?tabs=v7
Some prior examples of mine: