SkyWebFramework.DependencyInjection 1.0.0

dotnet add package SkyWebFramework.DependencyInjection --version 1.0.0
                    
NuGet\Install-Package SkyWebFramework.DependencyInjection -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SkyWebFramework.DependencyInjection" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SkyWebFramework.DependencyInjection" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SkyWebFramework.DependencyInjection" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SkyWebFramework.DependencyInjection --version 1.0.0
                    
#r "nuget: SkyWebFramework.DependencyInjection, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SkyWebFramework.DependencyInjection@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SkyWebFramework.DependencyInjection&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SkyWebFramework.DependencyInjection&version=1.0.0
                    
Install as a Cake Tool

SkyWebFramework.DependencyInjection

NuGet Version GitHub Repository License: MIT .NET

SkyWebFramework.DependencyInjection (EasyDI) is an enterprise-grade, high-performance convention and attribute-driven Dependency Injection framework for .NET 8 and .NET 9.

It eliminates repetitive builder.Services.AddScoped<...>() boilerplate code by automatically scanning assemblies, resolving conventions, supporting modular composition, applying decorators/interceptors, and detecting captive/circular dependencies at startup.



🌟 Key Features

  • ⚡ Zero-Boilerplate Assembly Scanning: Automatically discovers interfaces and implementations by naming conventions.
  • 🏷️ Attribute-Driven Lifetime Management: Decorate classes with [Scoped], [Transient], [Singleton], or [EasyService].
  • 🔑 Keyed Services (.NET 8/9): First-class support for [KeyedService("key")] with automatic interface inference.
  • 🧩 Modular DI Architecture: Organize registrations cleanly into decoupled modules (IEasyServiceModule) and profiles (IEasyServiceProfile) with priority ordering.
  • 🛡️ Diagnostic & Safety Engine: Built-in detection for Captive Dependencies (e.g. Scoped service inside Singleton) and Circular References.
  • 🎨 Decorator & Interceptor Patterns: Wrap services programmatically (services.Decorate<T, TDecorator>()) or via attributes ([Decorator(typeof(ITarget))]).
  • ⏳ Lazy Resolution (Lazy<T>): Defer instantiation of heavy services until .Value is accessed.
  • ⚙️ Flexible Configuration (EasyDiOptions): Custom type filters, namespace whitelist/blacklist, duplicate registration behaviors (Skip, Replace, Throw).

📦 Installation

Install via NuGet Package Manager:

dotnet add package SkyWebFramework.DependencyInjection

Or via Package Manager Console:

Install-Package SkyWebFramework.DependencyInjection

🛠️ Clone & Build Locally

To clone and build the source code locally:

git clone https://github.com/Skyrunner-Dev-ops/SkyWebFramework.DependencyInjection.git
cd SkyWebFramework.DependencyInjection
dotnet build -c Release

🚀 Quick Start

In your ASP.NET Core Program.cs:

using SkyWebFramework.DependencyInjection;

var builder = WebApplication.CreateBuilder(args);

// 1. One-line auto-registration for your entire assembly!
builder.Services.AddEasyServices();

// 2. (Optional) Auto-discover and run all IEasyServiceModule & IEasyServiceProfile instances
builder.Services.AddEasyServiceModules(Assembly.GetExecutingAssembly());

// 3. (Optional) Run container safety diagnostics at startup
builder.Services.DetectCaptiveDependencies(throwOnError: true);
builder.Services.ValidateEasyServices();

var app = builder.Build();
app.MapControllers();
app.Run();

💡 Usage Examples

1. Attribute-Driven Registration

Simply decorate your classes to define their lifetime:

using SkyWebFramework.DependencyInjection;

public interface IOrderService { void CreateOrder(); }

[Scoped]
public class OrderService : IOrderService
{
    public void CreateOrder() { /* Implementation */ }
}

[Singleton]
public class CacheService : ICacheService { }

[Transient]
public class PaymentGateway : IPaymentGateway { }

2. Convention-Based Scanning

Classes ending with Service, Repository, or Manager are automatically matched to I<ClassName> without requiring attributes!

// Automatically registered as Scoped under ICustomerRepository
public class CustomerRepository : ICustomerRepository { }

3. Keyed Services (.NET 8/9)

[KeyedService("email")]
public class EmailNotificationService : INotificationService { }

[KeyedService("sms")]
public class SmsNotificationService : INotificationService { }

// Consumer injection
public class NotificationController(
    [FromKeyedServices("email")] INotificationService emailService,
    [FromKeyedServices("sms")] INotificationService smsService)
{
    // ...
}

4. Modular Architecture (IEasyServiceModule)

Cleanly decouple registration logic across distinct feature modules:

[ServiceModule("BillingModule", Priority = 1)]
public class BillingModule : IEasyServiceModule
{
    public void RegisterServices(IServiceCollection services)
    {
        services.AddScoped<IBillingService, BillingService>();
    }
}

// Auto-register all modules in priority order
services.AddEasyServiceModules(Assembly.GetExecutingAssembly());

5. Decorators & Interceptors

// Programmatically decorate existing service registration
services.Decorate<IOrderService, LoggingOrderDecorator>();

// Attribute-driven decorator
[Decorator(typeof(ICalculatorService))]
public class AuditCalculatorDecorator : ICalculatorService
{
    private readonly ICalculatorService _inner;
    public AuditCalculatorDecorator(ICalculatorService inner) => _inner = inner;
    
    public int Add(int a, int b) => _inner.Add(a, b);
}

// Interceptor callback
services.InterceptService<IOrderService>((instance, provider) => 
{
    Console.WriteLine("Invoking OrderService");
    return instance;
});

6. Lazy Resolution (Lazy<T>)

// Enable Lazy<T> for all registered services
services.EnableLazyResolution();

// Service is NOT instantiated until .Value is accessed
public class ReportController(Lazy<IHeavyReportGenerator> lazyReportGenerator)
{
    public void Generate() => lazyReportGenerator.Value.Build();
}

7. Diagnostics & Container Summary

// Print a registration report to the console at startup
services.PrintEasyServiceSummary();

// Export full container state as formatted JSON
string jsonReport = services.ExportRegistrationsAsJson();

🤝 Contributing

Contributions are welcome! Please feel free to submit issues or pull requests on GitHub.

  1. Fork the Repository: https://github.com/Skyrunner-Dev-ops/SkyWebFramework.DependencyInjection
  2. Create your Feature Branch: git checkout -b feature/AmazingFeature
  3. Commit your Changes: git commit -m 'Add some AmazingFeature'
  4. Push to the Branch: git push origin feature/AmazingFeature
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License.

Copyright (c) 2026 Surya Pratap Singh - SkyWebFramework

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 97 8/25/2026