Puffix.IoC 3.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Puffix.IoC --version 3.1.0
NuGet\Install-Package Puffix.IoC -Version 3.1.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.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Puffix.IoC --version 3.1.0
#r "nuget: Puffix.IoC, 3.1.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.1.0

// Install Puffix.IoC as a Cake Tool
#tool nuget:?package=Puffix.IoC&version=3.1.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 net5.0 was computed.  net5.0-windows was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net6.0

    • No dependencies.
  • net7.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 797 11/28/2023
3.1.0 1,375 11/16/2022
3.0.0 2,554 5/13/2022
2.1.0 397 5/13/2022
2.0.0 1,747 11/11/2021
1.2.0 819 5/16/2021
1.1.0 1,240 7/20/2020
1.0.0 458 5/24/2020

Add public constructor