A compile-time checked dependency injection container for C# using Roslyn source generators.
StrongInject is a dependency injection container for C# that performs all dependency resolution checks at compile time using Roslyn source generators. It eliminates runtime errors by validating registrations during compilation and generates fast, reflection-free code for resolving dependencies. The container supports async initialization, scope management, and integrates with various .NET application types.
C# developers building .NET applications who need a performant, type-safe dependency injection solution, especially those targeting platforms like UWP or iOS where reflection is limited.
Developers choose StrongInject for its compile-time safety, which catches missing dependencies early, and its performance due to the absence of reflection. Its async support and modular design make it suitable for modern .NET applications.
compile time dependency injection for .NET
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Detects missing dependencies during compilation, not runtime, as shown in the example where omitting MyService registration causes a SI0102 error at build time.
Uses Roslyn source generators to generate fast, linker-friendly code, eliminating reflection overhead and ensuring compatibility with platforms like UWP and iOS.
Fully supports asynchronous initialization and disposal via IRequiresAsyncInitialization, allowing IO-bound tasks like database calls during resolution.
Offers a module system with RegisterModuleAttribute for reusable dependency groupings, enabling organized and maintainable container configurations.
Provides safe concurrent resolution and disposal, with guarantees that SingleInstance dependencies are created only once and no leaks occur during disposal.
Requires explicit registration via attributes and container classes for each dependency, which can be tedious and error-prone in large or complex projects.
Compared to established DI containers like Autofac or Microsoft.Extensions.DependencyInjection, it has fewer third-party integrations, community plugins, and is still under active development per the roadmap.
Demands understanding of source generators and StrongInject-specific patterns (e.g., Owned<T>, decorators), with error messages from compile-time checks potentially being cryptic for newcomers.
The compile-time nature limits dynamic scenarios, such as hot-reloading dependencies or runtime service selection without pre-registration, forcing workarounds like factory methods.