create-dbcontext

Generates per-bounded-context EF Core DbContext, constants, factory, and DI extension files.

Updated Nov 19, 2020
One-click install
npx skills add https://github.com/kwojtasinski-repo/ECommerceApp --skill create-dbcontext-kwojtasinski-repo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: create-dbcontext
Source: https://github.com/kwojtasinski-repo/ECommerceApp/tree/main/.github/skills/create-dbcontext
Command: npx skills add https://github.com/kwojtasinski-repo/ECommerceApp --skill create-dbcontext-kwojtasinski-repo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Setting up a new bounded context in this .NET e-commerce solution requires creating four boilerplate infrastructure files that must follow the ADR-0013 per-BC DbContext pattern, and hand-writing them risks inconsistent namespaces, missing UTC date handling, or wrong DI registration. ## Core Features & Use Cases - Four-file scaffolding: Generates the DbContext, schema Constants class, design-time DbContextFactory, and Infrastructure DI extension method in one pass. - Convention enforcement: Applies project rules such as internal sealed contexts, expression-bodied DbSet properties, UseUtcDateTimes, and configuration assembly filtering by namespace. - Use Case: When adding a new Sales/Orders bounded context, invoke the skill with the BC name, schema, and entity list to get all four files placed under ECommerceApp.Infrastructure with correct namespaces, then follow the listed manual steps for DI registration and EF configurations. ## Quick Start Ask the AI to create a per-BC DbContext for a given bounded context name, schema name, and comma-separated entity list, optionally with an infrastructure path like Sales/Orders.

Frequently Asked Questions about create-dbcontext

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a DbContext per bounded context in EF Core?

Provide the bounded context name, schema name, and entity list, and the skill generates the DbContext, constants, design-time factory, and DI extension files. The DbContext sets a default schema and applies configurations from the matching Configurations namespace.

What files does the per-BC DbContext scaffold generate?

It creates four files under ECommerceApp.Infrastructure: a DbContext class, a schema Constants class, an IDesignTimeDbContextFactory for dotnet ef commands, and an Extensions class with the AddInfrastructure DI registration method.

Why does the design-time factory use a hardcoded connection string?

The hardcoded connection string in the factory is intentional so the dotnet ef CLI can create the context at design time without app configuration. Runtime registration in Extensions.cs reads the connection string from IConfiguration instead.

Can I run EF Core migrations right after generating the DbContext?

No. The skill explicitly requires human approval before running migrations, per the project's migration policy. You must also register the DI extension, create EF configurations, and add repositories first.

What conventions does the generated DbContext follow?

The context is internal sealed, uses expression-bodied DbSet properties via Set<T>(), calls UseUtcDateTimes for UTC date handling, and filters ApplyConfigurationsFromAssembly to the bounded context's Configurations namespace.