back to home

DevTeam / Pure.DI

Pure DI for .NET

774 stars
28 forks
5 issues
C#HTMLBatchfile

AI Architecture Analysis

This repository is indexed by RepoMind. By analyzing DevTeam/Pure.DI in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.

Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.

Source files are only loaded when you start an analysis to optimize performance.

Embed this Badge

Showcase RepoMind's analysis directly in your repository's README.

[![Analyzed by RepoMind](https://img.shields.io/badge/Analyzed%20by-RepoMind-4F46E5?style=for-the-badge)](https://repomind.in/repo/DevTeam/Pure.DI)
Preview:Analyzed by RepoMind

Repository Overview (README excerpt)

Crawler view

Pure.DI for .NET **Pure.DI is a compile-time dependency injection (DI) code generator**. _Supports .NET starting with .NET Framework 2.0, released 2005-10-27, and all newer versions._ Usage Requirements • **.NET SDK 6.0.4+** Required for compilation. Projects can target older frameworks (e.g., .NET Framework 2.0). • **C# 8+** Only required for projects using the Pure.DI source generator. Other projects support any C# version. Key Features ✔️ Zero Overhead Pure.DI is a .NET code generator designed to produce clean, efficient dependency injection logic. By leveraging basic language constructs, it generates straightforward code indistinguishable from manual implementation—essentially composing objects through nested constructor invocations. Unlike traditional DI frameworks, Pure.DI avoids reflection and dynamic instantiation entirely, eliminating performance penalties associated with runtime overhead. ✔️ Compile-Time Validation All analysis of object, constructor, and method graphs occurs at compile time. Pure.DI proactively detects and alerts developers to issues such as missing dependencies, cyclic references, or dependencies unsuitable for injection—ensuring these errors are resolved before execution. This approach guarantees that developers cannot produce a program vulnerable to runtime crashes caused by faulty dependency wiring. The validation process operates seamlessly alongside code development, creating an immediate feedback loop: as you modify your code, Pure.DI verifies its integrity in real time, effectively delivering tested, production-ready logic the moment changes are implemented. ✔️ Works everywhere The pure dependency injection approach introduces no runtime dependencies and avoids .NET reflection , ensuring consistent execution across all supported platforms. This includes the Full .NET Framework 2.0+, .NET Core, .NET 5+, UWP/Xbox, .NET IoT, Unity, Xamarin, Native AOT, and beyond. By decoupling runtime constraints, it preserves predictable behavior regardless of the target environment. ✔️ Familiar Syntax The Pure.DI API is intentionally designed to closely mirror the APIs of mainstream IoC/DI frameworks. This approach ensures developers can leverage their existing knowledge of dependency injection patterns without requiring significant adaptation to a proprietary syntax. ✔️ Precise Generics Pure.DI recommends utilizing dedicated marker types rather than relying on open generics. This approach enables more precise construction of object graphs while allowing developers to fully leverage the capabilities of generic types. ✔️ Transparency Pure.DI allows to view and debug the generated code, making debugging and testing easier. ✔️ Built-in BCL Support Pure.DI provides native support for numerous Base Class Library (BCL) types out of the box without any extra effort. When to Use Pure.DI ✔️ High-Performance Applications Pure.DI is designed for high-performance applications where speed and minimal memory consumption are critical. ✔️ Projects with a Focus on Clean Code Pure.DI is suitable for projects where code cleanliness and minimalism are important factors. ✔️ Applications with Complex Dependencies Pure.DI can handle complex dependencies and provides flexible configuration options. ✔️ Ideal for Libraries Its high performance, zero memory consumption/preparation overhead, and lack of dependencies make it ideal for building libraries and frameworks. NuGet packages | NuGet package | Description | |-----------------------------------------------------------------------------|:--------------------------------------------------------------------| | Pure.DI | DI source code generator | | Pure.DI.Abstractions | Abstractions for Pure.DI | | Pure.DI.Templates | Template package, for creating projects from the shell/command line | | Pure.DI.MS | Add-ons for Pure.DI to work with Microsoft DI | Schrödinger's cat demonstrates how it all works The reality is Let's create an abstraction Here's our implementation > [!IMPORTANT] > Our abstraction and implementation know nothing about the magic of DI or any frameworks. Let's glue it all together Add the Pure.DI package to your project: Let's bind the abstractions to their implementations and set up the creation of the object graph: > [!NOTE] > In fact, the binding is unnecessary since Pure.DI supports many .NET BCL types out of the box, including Random. It was added just for the example of using the _Singleton_ lifetime. The code above specifies the generation of a partial class named *__Composition__*. This name is defined in the call. The class contains a *__Root__* property that returns an object graph with an object of type *__Program__* as the root. The type and name of the property are defined by calling . The generated code looks like this: Class diagram You can see the class diagram at any time by following the link in the comment of the generated class: This code does not depend on other libraries, does not use type reflection, and avoids tricks that can negatively affect performance and memory consumption. It looks like efficient code written by hand. At any given time, you can study it and understand how it works. The property is a *__Composition Root__*, the only place in the application where the composition of the object graph takes place. Each instance is created using basic language constructs, which compile with all optimizations and minimal impact on performance and memory consumption. In general, applications may have multiple composition roots and thus such properties. Each composition root must have its own unique name, which is defined when the method is called, as shown in the code above. Time to open boxes! Pure.DI creates efficient code in a pure DI paradigm, using only basic language constructs as if you were writing code by hand. This allows you to take full advantage of Dependency Injection everywhere and always, without any compromise! The full equivalent of this application with top-lev…