Skip to main content

Architecture: EF Core inside a Wisej.NET app

The Support Desk Data Console solution is created with Web, Data, Services and Tests projects, SupportDeskContext is registered through AddDbContextFactory (with a design-time factory), Microsoft's IServiceProvider is bridged into Wisej.NET, TicketQueryService arrives on the page through [Inject], and the first async count runs behind a loading guard and a friendly error message. Nothing is bound yet; that starts in Module 3.

Run it

cd "LearnWisej-Samples/Data Binding with EF Core Course/Module 1/SupportDesk.Web"
dotnet run -f net10.0 --urls http://localhost:5401

Then open http://localhost:5401. (Visual Studio: open SupportDesk.slnx, press F5; the port and the Development environment are in SupportDesk.Web/Properties/launchSettings.json.)

The web project multi-targets net10.0-windows;net10.0, so dotnet run needs -f. In Development the host creates SupportDesk.Web/App_Data/supportdesk.db on first start (EnsureCreated, twelve sample tickets); delete the file to start over.

Tests: dotnet test SupportDesk.Tests: three tests against SQLite in memory (count on empty, count on rows, one context created and disposed per operation).

What to try

The page has the two controls: countButton (Count tickets) and statusLabel.

  • Count tickets: the button is disabled, statusLabel reads Counting tickets..., then 12 tickets in the Support Desk database, and the button comes back.
  • Click twice quickly: the second click returns at the _loading guard; only one count runs.
  • Two sessions: open the page in two browser tabs and count in both; each gets its own result.
  • Database unreachable: start the app against a database it cannot open, for example set ASPNETCORE_ENVIRONMENT=Production and set ConnectionStrings__SupportDesk=Data Source=Z:/missing/supportdesk.db before dotnet run. Count tickets then shows a friendly AlertBox, statusLabel reads Count failed, the exception goes to the console log, and the button is enabled again.

Where things live

Module 1/
├─ SupportDesk.slnx the four projects
├─ SupportDesk.Web/ the Wisej.NET application (net10.0-windows;net10.0)
│ ├─ Startup.cs host: configuration → AddSupportDeskData → services → Build → IServiceProvider bridge → UseWisej
│ ├─ Program.cs Wisej.NET session entry point: Application.MainPage = new TicketBrowserPage()
│ ├─ TicketBrowserPage.cs [Inject] TicketQueryService, countButton_Click with the loading guard
│ ├─ TicketBrowserPage.Designer.cs countButton, statusLabel
│ ├─ SupportDeskDevelopmentDatabase.cs Development only: EnsureCreated + twelve sample tickets at host start
│ └─ appsettings.json ConnectionStrings:SupportDesk = Data Source=App_Data/supportdesk.db
├─ SupportDesk.Data/ EF Core lives here (the only project referencing the provider)
│ ├─ SupportDeskContext.cs the unit of work (Module 1: one minimal Ticket entity)
│ ├─ Entities/Ticket.cs
│ ├─ SupportDeskDesignTimeFactory.cs IDesignTimeDbContextFactory for dotnet ef
│ ├─ SupportDeskPaths.cs resolves the relative SQLite path for the app, the tests and dotnet ef
│ ├─ DependencyInjection/…Extensions.cs AddSupportDeskData: AddDbContextFactory + UseSqlite + dev diagnostics
│ └─ Diagnostics/ QueryTrace + QueryTraceInterceptor, used by the tests to count contexts and statements
├─ SupportDesk.Services/
│ └─ TicketQueryService.cs CountTicketsAsync (one context per call)
├─ SupportDesk.Tests/ xunit, SQLite in memory (SqliteTestFactory)
└─ docs/ the five deliverables