Skip to content

Commit d20aea3

Browse files
csharpfritzCopilot
andcommitted
docs(skills): add Required DI Services section to migration-standards
ContosoUniversity Run 05 findings: - AddHttpContextAccessor() is required for BWFC data controls - EnsureCreated() needed at startup for database initialization - Without these, pages with GridView/DetailsView return HTTP 500 Test score: 22/40 (55%) up from 21/40 (52.5%) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0a062b3 commit d20aea3

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

  • migration-toolkit/skills/migration-standards

migration-toolkit/skills/migration-standards/SKILL.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ source: "earned"
77
---
88

99
<!-- Updated 2026-03-09: Added ASPX URL rewriting standard (ContosoUniversity Run 04) -->
10+
<!-- Updated 2026-03-09: Added required DI services (ContosoUniversity Run 05) -->
1011

1112
## Context
1213

@@ -78,6 +79,40 @@ The Layer 1 script's `Wrap-GridViewColumns` function handles this automatically.
7879
| ListView | `ItemType` | `<ListView ItemType="Product" ...>` |
7980
| FormView | `ItemType` | `<FormView ItemType="Order" ...>` |
8081

82+
### Required DI Services
83+
84+
**The following services MUST be registered for BWFC components to work correctly:**
85+
86+
```csharp
87+
// Program.cs — required service registrations
88+
89+
var builder = WebApplication.CreateBuilder(args);
90+
91+
// Required for BWFC components (GridView, DetailsView, etc.)
92+
builder.Services.AddHttpContextAccessor();
93+
94+
// BWFC services — call AFTER AddHttpContextAccessor
95+
builder.Services.AddBlazorWebFormsComponents();
96+
97+
// Entity Framework — initialize schema at startup
98+
var app = builder.Build();
99+
using (var scope = app.Services.CreateScope())
100+
{
101+
var db = scope.ServiceProvider.GetRequiredService<YourDbContext>();
102+
db.Database.EnsureCreated();
103+
}
104+
```
105+
106+
**Why `AddHttpContextAccessor()` is required:**
107+
- BWFC's GridView, DetailsView, and other components inject `IHttpContextAccessor`
108+
- Without this registration, pages using BWFC data controls fail with HTTP 500
109+
- Error: "Cannot provide a value for property 'HttpContextAccessor' on type 'GridView'"
110+
111+
**Why `EnsureCreated()` at startup:**
112+
- Creates database schema from EF Core model if it doesn't exist
113+
- Without this, database queries fail on empty/non-existent database
114+
- For production, consider EF Core migrations instead
115+
81116
**Derive the type from:**
82117
1. The `ItemType` attribute in Web Forms markup (if present)
83118
2. The `SelectMethod` return type in the code-behind

0 commit comments

Comments
 (0)