Remnant.Dependency.Injector 2.0.0

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

// Install Remnant.Dependency.Injector as a Cake Tool
#tool nuget:?package=Remnant.Dependency.Injector&version=2.0.0                

Remnant Dependency Injector

  • Install nuget package:

      Install-Package Remnant.Dependency.Injector -Version 2.0.0
    
  • The injection follows a pull pattern unlike all other DI containers which uses a push pattern

  • The pull pattern has no need to declare constructor arguments for DI, also no hierarchical DI wiring is required

  • The DI container is global accessible within your current app domain

  • Anywhere, any place in your code the DI container can be requested to resolve the object needed

  • An extension method 'Resolve<<TType>>' is implemented on 'object' to allow any objects to call the container

  • You can use the [Inject] attribute on fields which will automatically inject the dependency object

Note: When using the [Inject] attribute to decorate class fields, your class must be specified as partial.

Important: If your class already contains an empty parameter constructor: <br/>

  • The analyzer can't generate a constructor with the injection code because the method (constructor) exists already
  • In that case the Analyzer generates a public 'Inject' method, as well as a static 'Create' method on the class
  • So you can call the static 'Create' method which will create an instance of the class and it calls the 'Inject' method to perform the injection
  • Or you can instantiate the class and call the 'Inject' method yourself
  • Keep in mind on your constructor, the injected fields will be null (unless you call 'Inject()' as the first thing on your constructor)
  • Ensure that the specified injected fields are not <b>readonly</b>
  • <i>(see example 4)</i>.

Quick console app examples (<a href="https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/top-level-statements">using top-level statements feature</a>):

Example 1: register something with the container (used by all examples)
using ConsoleApp;
using Remnant.Dependency.Injector;

DIContainer
  .Create("MyContainer")
  .Register(new List<string> { "John", "Jane" }, "Names");
Example 2: using extension method 'Resolve' on object
new object()
  .Resolve<List<string>>("Names")
  .ForEach(name => Console.WriteLine(name));
}
Example 3: using 'Inject' attribute
new Members().ListNames();
// Members.cs
using Remnant.Dependency.Injector;

namespace ConsoleApp
{
  public partial class Members
  {
    [Inject("Names")]
    private readonly List<string> _names;
    public void ListNames() => _names.ForEach(name => Console.WriteLine(name));
  }
}
Example 4: using static 'Create' method
//... static 'Create' member is generated which will do injection
Members.Create().ListNames();
// Members.cs
using Remnant.Dependency.Injector;

namespace ConsoleApp
{
  public partial class Members
  {
    [Inject("Names")]
    private List<string> _names; //must not be readonly

    public Members()
    {
      Console.WriteLine("Remnant code analyzer can not generate a constructor for injection, thus use generated static 'Create' member.");
    }

    public void ListNames() => _names.ForEach(name => Console.WriteLine(name));
  }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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 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.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on Remnant.Dependency.Injector:

Package Downloads
Remnant.Dependency.CastleWindsor

Castle Windsor dependency injection adapter

Remnant.Dependency.Ninject

Ninject dependency injection adapter

Remnant.Dependency.SimpleInjector

Simple Injector dependency injection adapter

Remnant.Dependency.Autofac

Autofac dependency injection adapter

Remnant.Dependency.Unity

Unity dependency injection adapter

GitHub repositories

This package is not used by any popular GitHub repositories.

First release