ricaun.DI 1.0.0

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package ricaun.DI --version 1.0.0
NuGet\Install-Package ricaun.DI -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="ricaun.DI" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ricaun.DI --version 1.0.0
#r "nuget: ricaun.DI, 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.
// Install ricaun.DI as a Cake Addin
#addin nuget:?package=ricaun.DI&version=1.0.0

// Install ricaun.DI as a Cake Tool
#tool nuget:?package=ricaun.DI&version=1.0.0

ricaun.DI

Visual Studio 2022 Nuke License MIT Build Release

ricaun.DI

Create a Container and register your dependencies with AddSingleton, AddScoped and AddTransient methods. Resolve your dependencies with Resolve method.

ricaun.Revit.DI

To use this library in Autodesk Revit, use the ricaun.Revit.DI library.

Implementation Reference

This project uses the same implementation from Onbox IOC container system, except by:

The Container when Dispose can dispose all IDisposable scoped instances registered in the container.

Container

// Empty Container.
Container container = new Container();
// Dispose Container.
container.Dispose();

ContainerUtils

// Create Container with itself registered as a singleton.
IContainer container = ContainerUtils.CreateContainer();
// Create Container with itself registered as a singleton, with dispose scoped instances enabled.
IContainer container = ContainerUtils.CreateContainer(true);

Singleton

// Register a singleton.
var singleton = new Singleton();
container.AddSingleton(singleton);
container.AddSingleton<ISingleton>(singleton);
container.AddSingleton<ISingleton, Singleton>();
container.AddSingleton<ISingleton, Singleton>(singleton);

Scoped

// Register a scoped.
container.AddScoped<Scoped>();
container.AddScoped<IScoped, Scoped>();

Transient

// Register a transient.
container.AddTransient<Transient>();
container.AddTransient<ITransient, Transient>();

Resolve

// Resolve the ISingleton.
var singleton = container.Resolve<ISingleton>();
// Resolve the IScoped.
var scoped = container.Resolve<IScoped>();
// Resolve the ITransient.
var transient = container.Resolve<ITransient>();

ResolveOrNull

// Resolve the ISingleton.
var singleton = container.ResolveOrNull<ISingleton>();
// Resolve the IScoped.
var scoped = container.ResolveOrNull<IScoped>();
// Resolve the ITransient.
var transient = container.ResolveOrNull<ITransient>();

Enable Console

// Enable Console.
container.EnableConsolePrinting(true);

Enable Dispose Scoped Instances

// Enable Dispose Scoped Instances.
container.EnableDisposeScopedInstances(true);

Static Container Example

Simple Host static class to hold the container.

using ricaun.DI;
public static class Host
{
    public static IContainer Container { get; } = ContainerUtils.CreateContainer();
    public static IContainerResolver ContainerResolver => Container;
    public static T Resolve<T>() where T : class => ContainerResolver.Resolve<T>();
    public static T ResolveOrNull<T>() where T : class => ContainerResolver.ResolveOrNull<T>();
}

Extension for the IHost interface.

public interface IHost { }
public static class HostExtension
{
    public static IContainer GetContainer(this IHost _) => Host.Container;
    public static IContainerResolver GetContainerResolver(this IHost _) => Host.ContainerResolver;
    public static T Resolve<T>(this IHost _) where T : class => Host.Resolve<T>();
    public static T ResolveOrNull<T>(this IHost _) where T : class => Host.ResolveOrNull<T>();
}

Release

License

This project is licensed under the MIT Licence.


Do you like this project? Please star this project on GitHub!

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 was computed. 
.NET Framework net40 is compatible.  net403 was computed.  net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  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.
  • .NETFramework 4.0

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • net5.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ricaun.DI:

Package Downloads
ricaun.Revit.DI The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Dependency injection container for Revit.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 293 12/22/2023