Puffix.IoC 3.2.0

dotnet add package Puffix.IoC --version 3.2.0
NuGet\Install-Package Puffix.IoC -Version 3.2.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="Puffix.IoC" Version="3.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Puffix.IoC --version 3.2.0
#r "nuget: Puffix.IoC, 3.2.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.
// Install Puffix.IoC as a Cake Addin
#addin nuget:?package=Puffix.IoC&version=3.2.0

// Install Puffix.IoC as a Cake Tool
#tool nuget:?package=Puffix.IoC&version=3.2.0

Puffix IoC

Minimal library to map your IoC container in your project, and remain independent from IoC Framework in your base code.

NuGet version (Puffix.IoC) Build status

In the sample below, Autofac is used.

First, a base class is needed to reference the objects to map:

using Autofac;
using Puffix.IoC;

namespace YourAppName;

public class IoCContainer : IIoCContainer
{
    private readonly IContainer? container;

    public IoCContainer(ContainerBuilder containerBuilder)
    { 
        // Self-register the container.
        containerBuilder.Register(_ => this).As<IIoCContainer>().SingleInstance();

        container = containerBuilder.Build();
    }

    public static IIoCContainer BuildContainer()
    {
        ContainerBuilder containerBuilder = new ContainerBuilder();
        containerBuilder.RegisterAssemblyTypes
                        (
                            typeof(IoCContainer).Assembly // Current Assembly.
                        )
                        .AsSelf()
                        .AsImplementedInterfaces();

        containerBuilder.RegisterInstance(configuration).SingleInstance();

        return new IoCContainer(containerBuilder);
    }

    public ObjectT Resolve<ObjectT>(params IoCNamedParameter[] parameters)
        where ObjectT : class
    {
        if (container == null)
            throw new ArgumentNullException($"The class {GetType().Name} is not well initialized.");

        ObjectT resolvedObject;
        if (parameters != null)
            resolvedObject = container.Resolve<ObjectT>(ConvertIoCNamedParametersToAutfac(parameters));
        else
            resolvedObject = container.Resolve<ObjectT>();

        return resolvedObject;
    }

    public object Resolve(Type objectType, params IoCNamedParameter[] parameters)
    {
        if (container == null)
            throw new ArgumentNullException($"The class {GetType().Name} is not well initialized.");

        object resolvedObject;
        if (parameters != null)
            resolvedObject = container.Resolve(objectType, ConvertIoCNamedParametersToAutfac(parameters));
        else
            resolvedObject = container.Resolve(objectType);

        return resolvedObject;
    }

    private IEnumerable<NamedParameter> ConvertIoCNamedParametersToAutfac(IEnumerable<IoCNamedParameter> parameters)
    {
        foreach (var parameter in parameters)
        {
            if (parameter != null)
                yield return new NamedParameter(parameter.Name, parameter.Value);
        }
    }
}

The container must be initialized:

IIoCContainer container = IoCContainer.BuildContainer();

An the you can resolve your objects in the code:

MyObject myObject = container.Resolve<MyObject>();
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Puffix.IoC:

Package Downloads
Puffix.IoC.Configuration

Extension for including Microsoft.Extension.Configuration in the Puffix IoC library.

Puffix.Cqrs.IoC

IoC extension for puffix CQRS framework implementation.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.2.0 788 11/28/2023
3.1.0 1,372 11/16/2022
3.0.0 2,553 5/13/2022
2.1.0 396 5/13/2022
2.0.0 1,746 11/11/2021
1.2.0 818 5/16/2021
1.1.0 1,239 7/20/2020
1.0.0 457 5/24/2020

Add public constructor