Skip to content

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dotnet_advanced_2026

Set Up and Use

GitHub CoPilot

This example used GitHub CoPilot with manual oversight guiding the creation of numerous Dependency Injection, Database Caching, and Docker entrypoint.sh examples.

Docker

Docker Compose:

docker compose up

Uses a custom ENTRYPOINT that waits for MSSQL readiness and automatically runs mssql/init_sql.sql with sqlcmd. The script is safe to rerun when the container restarts. (Thanks AI!)

Topics

.NET CLI

dotnet new mvc --language "C#"
dotnet run

# For less detailed tests
dotnet test

ASP.NET

Views and Endpoints:

Interface and Dependency Injection:

Caching

dotnet add package Microsoft.Extensions.Caching.Memory

Database query caching:

  • ExampleQueryService keeps the first query result in its scoped instance as a first-level cache.
  • IMemoryCache stores the result across scopes as a second-level cache for five minutes, with a one-minute sliding expiration.
  • https://0.0.0.0:5177/Example/SqlExamples

Tests

Tests use asp_entity/tests/asp_entity.runsettings for detailed per-test console output, while the xUnit configuration enables diagnostic messages and full test method names. Run them with:

# From the top-level root directory
dotnet test asp_entity/tests/asp_entity.Tests.csproj

EntityFrameworkCore

Already run from within asp_entity/src:

# The versions should match
dotnet add package Microsoft.EntityFrameworkCore --version 10.0.11
dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 10.0.11

If those versions mismatch:

asp_entity-1  | Using launch settings from /app/src/Properties/launchSettings.json...
asp_entity-1  | Building...
asp_entity-1  | /app/src/asp_entity.csproj : error NU1605: Warning As Error: Detected package downgrade: Microsoft.EntityFrameworkCore from 10.0.11 to 10.0.0. Reference the package directly from the project to select a different version. 
asp_entity-1  | /app/src/asp_entity.csproj : error NU1605:  asp_entity -> Microsoft.EntityFrameworkCore.SqlServer 10.0.11 -> Microsoft.EntityFrameworkCore.Relational 10.0.11 -> Microsoft.EntityFrameworkCore (>= 10.0.11) 
asp_entity-1  | /app/src/asp_entity.csproj : error NU1605:  asp_entity -> Microsoft.EntityFrameworkCore (>= 10.0.0)
asp_entity-1  | 
asp_entity-1  | The build failed. Fix the build errors and run again.

MSSQL

Exercise in MSSQL admin.

  1. docker-entrypoint-initdb.d isn't supported within the Docker Container but I've kept the convention for familiarity's sake.
    • This: /opt/mssql-tools18/bin/sqlcmd -U sa -P FD83wr9DF_*9pke89 -S localhost -No -i docker-entrypoint-initdb.d/init_sql.sql is now executed using entrypoint.sh.
    • Since initialization doesn't happen immediately, I've added sleep 120 to the Bash script.
    • Some of the issues identified here can be side-stepped on macOS 26.6.

The Docker Container uses Kerberos authentication which should be configured. Use the following to verify the above using an inline query and script:

/opt/mssql-tools18/bin/sqlcmd -U sa -P FD83wr9DF_*9pke89 -S localhost -No -i docker-entrypoint-initdb.d/init_sql.sql
# Must use dbo syntax inline
/opt/mssql-tools18/bin/sqlcmd -U sa -P FD83wr9DF_*9pke89 -S localhost -Q "SELECT * FROM TestDB.dbo.Example;" -C
/opt/mssql-tools18/bin/sqlcmd -U sa -P FD83wr9DF_*9pke89 -S localhost -No -i docker-entrypoint-initdb.d/verify_sql.sql

https://learn.microsoft.com/en-us/sql/sql-server/?view=sql-server-ver16

Resources and Links

  1. https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection/service-lifetimes
  2. https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection/guidelines

About

Dependency Injection, Caching, Entrypoint for MSSQL

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages