$ show autofac/Autofac
Autofac is a mature, production-grade Inversion of Control (IoC) container for .NET, providing dependency injection (DI) capabilities. The core library manages object lifetimes, service resolution, and dependency graphs through a fluent registration API and a pipeline-based resolution engine. It supports a wide range of features including constructor and property injection, decorators, open generics, assembly scanning, metadata, keyed services, and advanced lifetime scopes (singleton, per-scope, per-dependency, per-owned). The architecture is built around extensible middleware phases (scope selection, decoration, sharing, activation) and registration sources that dynamically provide services. Autofac is designed for high performance and AOT/trimming compatibility, with extensive benchmarks and a dedicated AOT verification workflow. It is a library, not an application; it is consumed by other .NET projects to manage their dependency injection needs.
The LLM identified 5 files worth highlighting for reuse:
Implements the resolve pipeline as a doubly-linked list of middleware phases (ScopeSelection, Decoration, Sharing, Activation, etc.). Supports insertion modes (StartOfPhase, EndOfPhase) and compiles the pipeline into a single delegate for performance. This pattern allows third-party extensions to customize resolution behavior without modifying core code.
Defines the IRegistrationSource interface for dynamically providing component registrations at runtime. Implementations like MetaRegistrationSource, LazyRegistrationSource, and OwnedInstanceRegistrationSource enable implicit support for relationship types (Lazy<T>, Meta<T>, Owned<T>) without explicit registration. This pattern is highly reusable for any DI container needing on-the-fly service generation.
Centralized cache for reflection metadata (constructor binders, property setters, type information) with support for weak references and assembly unloading. Uses a set of typed dictionaries (ReflectionCacheDictionary<TKey,TValue>) that can be cleared based on predicates. This pattern avoids repeated reflection calls and is critical for performance in DI containers.
Implements the decorator pattern as a middleware in the resolve pipeline. Supports conditional decoration, injection of IDecoratorContext, lifetime inheritance, and open generic decorators. The decorator service is resolved and wrapped around the decorated instance, with proper disposal chaining. This is a clean, reusable implementation of the decorator pattern for DI.
A Roslyn incremental source generator that produces repetitive Register extension methods and DelegateInvoker classes for delegate-based registrations with up to 10 dependencies. Reduces boilerplate and ensures type safety. The generated code is verified via snapshot tests, making it a reliable pattern for automating repetitive API surface.