unity-di

Configure Unity DI dependencies with lifetimes and resolutions for ASP.NET MVC 5 and Web API 2 projects.

Updated Mar 2, 2026
One-click install
npx skills add https://github.com/FerranGuardia/claude-autonomous-setup --skill unity-di
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unity-di
Source: https://github.com/FerranGuardia/claude-autonomous-setup/tree/main/skills/backend/unity-di
Command: npx skills add https://github.com/FerranGuardia/claude-autonomous-setup --skill unity-di

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Unity DI for .NET Framework apps often lacks clear guidance on container setup, lifetime management, and ASP.NET integration. This Skill consolidates common patterns (constructor and property injection, per-request scopes, named registrations) into a reusable recipe that reduces boilerplate and prevents misconfigurations.

Core Features & Use Cases

  • Container setup and registration patterns that map interfaces to implementations with configurable lifetimes.
  • ASP.NET MVC 5 and Web API 2 integration with per-request scoping via hierarchical lifetime management.
  • Injection patterns including constructor and property injection, with support for named registrations and resolution.
  • Registration by convention and common pitfalls guidance to prevent misuse and ensure testability.

Quick Start

Configure Unity DI in your ASP.NET project by registering types and lifetimes, then resolve services in controllers.

Frequently Asked Questions about unity-di

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

FAQPage Schema
How do I configure Unity DI container for ASP.NET MVC 5 and Web API 2?

Configure Unity DI by registering types with configurable lifetimes and integrating per-request scoping via hierarchical lifetime management for ASP.NET MVC 5 and Web API 2 projects. This ensures proper container resolution and dependency injection across controllers.

What is per-request scope lifetime management in Unity dependency injection?

Per-request scope lifetime management in Unity DI uses hierarchical lifetime management to ensure resolved dependencies are scoped to a single HTTP request. This prevents shared state issues and ensures proper disposal of scoped services in ASP.NET applications.

How do I set up named registrations and resolution by convention in Unity DI?

Unity DI supports registration by convention to map interfaces to implementations automatically, alongside named registrations for resolving multiple implementations of the same interface. This reduces boilerplate configuration and ensures testability across large codebases.

Does Unity DI support both constructor and property injection in .NET Framework apps?

Yes, Unity DI supports both constructor and property injection patterns in .NET Framework apps. Constructor injection is used for required dependencies while property injection handles optional dependencies, with configurable lifetimes managing resolution behavior.

What are common Unity DI misconfigurations and pitfalls in large .NET codebases?

Common Unity DI pitfalls include incorrect lifetime management causing captive dependencies, missing per-request scoping in ASP.NET, and improper registration-by-convention setups. Following consolidated patterns for container setup and registration prevents misconfigurations and ensures testability.

Why does my Unity DI resolution fail with per-request lifetime in Web API 2?

Unity DI per-request lifetime resolution failures in Web API 2 typically stem from missing hierarchical lifetime management configuration or improper container setup. Ensuring correct per-request scoping integration and proper registration of dependencies across the dependency chain resolves these issues.