dependency-injection-autofac

Wire Autofac dependency injection across Domain, Application, and Infrastructure layers.

Updated Apr 29, 2026
One-click install
npx skills add https://github.com/bbolek-ap/new-ai-native --skill dependency-injection-autofac
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dependency-injection-autofac
Source: https://github.com/bbolek-ap/new-ai-native/tree/main/.claude/skills/dependency-injection-autofac
Command: npx skills add https://github.com/bbolek-ap/new-ai-native --skill dependency-injection-autofac

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Autofac-based module wiring organizes dependency injection across service layers (Domain, Application, Infrastructure) to support clean architecture with centralized registrations and correct lifetimes.

Core Features & Use Cases

  • Module-per-layer pattern: one Autofac Module per layer (Domain, Application, Infrastructure) to organize registrations.
  • MediatR and Validators: register MediatR handlers and FluentValidation validators via assembly scanning.
  • DbContext and repositories: register EF Core DbContext and repository implementations with proper lifetimes.
  • Program.cs host integration: wire Autofac into the Api host as the DI container.
  • Lifetime guidance: recommended lifetimes for DbContext, repositories, MediatR handlers, and HTTP clients.

Quick Start

Create a Module that registers DomainModule, ApplicationModule, and InfrastructureModule and wire it into the Api host.

Frequently Asked Questions about dependency-injection-autofac

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

FAQPage Schema
How do I wire Autofac modules for dependency injection across layered .NET architectures?

Wiring Autofac modules for dependency injection involves creating one Autofac Module per layer (Domain, Application, Infrastructure) to organize registrations. This module-per-layer pattern ensures centralized registrations and correct lifetimes for scalable, testable application wiring.

How do I register MediatR handlers and FluentValidation validators with Autofac?

Register MediatR handlers and FluentValidation validators with Autofac using assembly scanning within the Application layer's module. This approach automatically discovers and wires handlers and validators, simplifying configuration and maintaining clean architecture boundaries.

What is the recommended Autofac lifetime scope for DbContext and repositories in clean architecture?

The recommended Autofac lifetime scope for DbContext and repositories ensures scoped or per-request lifetimes, preventing concurrency issues. Applying defined lifetimes per component guarantees that EF Core DbContext and repository implementations maintain scalable and testable application wiring.

Does this Autofac dependency injection approach work with service-oriented projects using Domain, Application, and Infrastructure layers?

Yes, this Autofac dependency injection approach works specifically for service-oriented projects using Domain, Application, and Infrastructure layers. It covers module loading, registration in the API host, and defined component lifetimes to support clean architecture.

How do I integrate Autofac as the DI container in my .NET API host Program.cs?

Integrate Autofac as the DI container in your .NET API host Program.cs by wiring Autofac modules into the host configuration. You create a main module that registers DomainModule, ApplicationModule, and InfrastructureModule to centralize application wiring.

Why use a module-per-layer pattern for dependency injection instead of centralized registration?

Using a module-per-layer pattern for dependency injection organizes registrations cleanly across Domain, Application, and Infrastructure layers. This separation ensures scalable, testable, and maintainable application wiring compared to monolithic centralized registration approaches.