BareboneDI 1.0.4

dotnet add package BareboneDI --version 1.0.4
                    
NuGet\Install-Package BareboneDI -Version 1.0.4
                    
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="BareboneDI" Version="1.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BareboneDI" Version="1.0.4" />
                    
Directory.Packages.props
<PackageReference Include="BareboneDI" />
                    
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 BareboneDI --version 1.0.4
                    
#r "nuget: BareboneDI, 1.0.4"
                    
#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 BareboneDI@1.0.4
                    
#: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=BareboneDI&version=1.0.4
                    
Install as a Cake Addin
#tool nuget:?package=BareboneDI&version=1.0.4
                    
Install as a Cake Tool

BareboneDI – Lightweight Dependency Injection for .NET Framework

Package: BareboneDI
Target Framework: .NET Framework 4.7.2+
Author: Orhan Fırtına
Version: 1.0.0


📌 What is BareboneDI?

BareboneDI is a lightweight, extensible Dependency Injection container designed to bring modern IoC container capabilities to legacy and enterprise .NET Framework projects. It provides powerful features similar to Autofac or SimpleInjector but is implemented from scratch with full source code transparency and no external dependencies.


✅ Key Features

  • ✅ Open Generic Registrations
  • ✅ Keyed / Named Registrations
  • ✅ Property Injection ([Inject] attribute)
  • ✅ Lifetime Management: Transient, Singleton, Scoped
  • ✅ Lifetime Scopes (Nested containers)
  • ✅ Auto Registration (Assembly Scanning)
  • ✅ Module Support
  • ✅ Factory / Delegate Registration
  • ✅ Parameter Overrides
  • ✅ IEnumerable<T> Collection Resolution
  • ✅ Interception Stub (RealProxy / DispatchProxy Ready)

🚀 Getting Started

Step 1: Install the NuGet Package

Add BareboneDI to your project:

PM> Install-Package BareboneDI

Or reference the .nupkg locally if you're consuming it internally.

Step 2: Configure Your DI Container

public static class DIConfig
{
    public static DependencyContainer Container { get; private set; }

    public static void RegisterServices()
    {
        Container = new DependencyContainer();

        // Regular Registration
        Container.Register<ILogger, ConsoleLogger>(Lifetime.Singleton);

        // Open Generic Registration
        Container.Register<IRepository<>, Repository<>>(Lifetime.Transient);

        // Keyed Registration
        Container.Register<IPaymentService, CreditCardPayment>(Lifetime.Transient, "Credit");
        Container.Register<IPaymentService, PayPalPayment>(Lifetime.Transient, "PayPal");

        // Factory Registration
        Container.Register<ISettings>(c => new Settings("prod"), Lifetime.Singleton);

        // Auto Registration (e.g., all *Service classes)
        Container.RegisterAssemblyTypes(Assembly.GetExecutingAssembly(), t => t.Name.EndsWith("Service"));

        // Module Registration
        Container.RegisterModule(new CoreModule());
    }
}

Step 3: Hook into Web API

GlobalConfiguration.Configuration.DependencyResolver = new BareboneDIResolver(DIConfig.Container);

🧪 Usage Examples

1. Constructor Injection

public class CustomerController : ApiController
{
    private readonly ILogger _logger;
    private readonly IRepository<Customer> _repository;

    public CustomerController(ILogger logger, IRepository<Customer> repository)
    {
        _logger = logger;
        _repository = repository;
    }
}

2. Property Injection

public class OrderController : ApiController
{
    [Inject]
    public IOrderService OrderService { get; set; }
}

3. Keyed Resolution

var payPal = Container.Resolve<IPaymentService>("PayPal");

4. Lifetime Scopes

using (var scope = Container.BeginLifetimeScope())
{
    var unitOfWork = scope.Resolve<IUnitOfWork>();
}

5. Parameter Overrides

var overrides = new Dictionary<string, object> { { "connectionString", "MyConn" } };
var dbService = Container.Resolve<IDatabaseService>(overrides);

6. IEnumerable<T> Support

public class MultiLogger : ILogger
{
    public MultiLogger(IEnumerable<ILogger> loggers) { ... }
}

7. Module Definition

public class CoreModule : Module
{
    public override void Load(DependencyContainer container)
    {
        container.Register<ILogger, FileLogger>(Lifetime.Singleton);
        container.Register<IUserService, UserService>();
    }
}

🧩 Architecture Overview

  • DependencyContainer: Core registration and resolution logic
  • LifetimeScope: Manages per-scope instance cache
  • Registration: Holds metadata for each service (type, lifetime, factory, singleton cache)
  • InjectAttribute: Marks a property as injectable
  • Module: Supports grouped service loading

🛠️ Custom Interception

The ApplyInterceptors() method is a stub. You can extend it with RealProxy or DispatchProxy to implement:

  • Logging
  • AOP validations
  • Dynamic decorators

📄 License

MIT License – free for commercial and open-source usage.


👋 Author

Orhan Fırtına
Contact: LinkedIn

Product Compatible and additional computed target framework versions.
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

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.4 152 4/18/2025
1.0.3 147 4/18/2025
1.0.2 145 4/18/2025
1.0.1 186 4/13/2025
1.0.0 148 4/12/2025

Initial release