dbcontext-and-services

Configure EF Core DbContext lifecycles and DI service registrations.

14.8k|3.4k|Updated Jan 23, 2014
One-click install
npx skills add https://github.com/dotnet/efcore --skill dbcontext-and-services
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dbcontext-and-services
Source: https://github.com/dotnet/efcore/tree/main/.agents/skills/dbcontext-and-services
Command: npx skills add https://github.com/dotnet/efcore --skill dbcontext-and-services

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

EF Core DbContext and DI service infrastructure guidance for consistent lifecycle management across apps.

Core Features & Use Cases

  • Centralized DbContext lifecycle handling and DI service registration patterns.
  • Demonstrations of the Dependencies pattern using sealed records for dependencies.
  • Guidance on DbContext pooling, lifetimes, and CoreServices dictionary usage.

Quick Start

Configure a DbContext with generic registration patterns and a DI container setup to enforce scoped lifetimes.

Frequently Asked Questions about dbcontext-and-services

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

FAQPage Schema
How do I register an EF Core DbContext with dependency injection?

Register an EF Core DbContext using generic service registration patterns within a DI container to enforce scoped service lifetimes and centralize context configuration across your application.

What is the Dependencies pattern using sealed records in .NET?

The Dependencies pattern using sealed records provides typed service registration by mapping CoreServices dependencies into immutable records managed by the DI container.

How does DbContext pooling affect service lifetimes?

DbContext pooling reuses context instances to optimize performance, requiring careful DI service lifetime configuration to ensure pooled contexts integrate correctly with scoped service registrations.

Can I use a CoreServices dictionary for typed service registrations?

Yes, a CoreServices dictionary supports typed service registrations by mapping dependency keys to their implementations, enabling structured service resolution within the DI infrastructure.

When do I need to configure scoped lifetimes for EF Core?

Configure scoped lifetimes for EF Core when registering DbContexts and related services to ensure consistent lifecycle management and prevent concurrency issues across user requests.

What is the best way to manage DbContext lifecycles in .NET?

The best way to manage DbContext lifecycles is to apply centralized DI service registration patterns, utilizing pooling and scoped lifetimes to enforce consistent context configuration across apps.