Pygmalions.Prism.Injecting 1.0.4

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

// Install Pygmalions.Prism.Injecting as a Cake Tool
#tool nuget:?package=Pygmalions.Prism.Injecting&version=1.0.4                

Prism Injecting

This plugin provides a mechanism to do proactive dependency injection, which means the object to inject proactively get the injection content from the container.

How to Use

Injections can be gotten with its type category and its optional ID. If a field or property is marked with [Inject] attribute, then this plugin will generate proactive getter for it; and if the property necessary is true (by default), then an exception will be thrown if the corresponding injection is missing from the container.

For example, this is the code of the class to inject:

public class SampleObject
{
    [Inject(necessary: false)]
    public int IntValue = -1;

    [Inject(id: "IntInjection", necessary: false)]
    public int IntValueWithId = -1;

    [Inject(typeof(string), necessary: false)]
    public string StringText = "";
}

Initialize the proxy generator and load this plugin:

var generator = new Generator();
generator.RegisterPlugin(new InjectionPlugin());

Create an instance of the proxy class:

var instance = Activator.CreateInstance(generator.GetProxy<SampleObject>()) as SampleObject;

Convert it to the IInjectable interface:

var proxy = (IInjectable)instance;

Prepare the container:

var container = new InjectionContainer();
container.Add(typeof(int), 3);
// or, add a value creator to the container.
container.Add(typeof(int), () => 3);

Inject the object with the container:

proxy.Inject(container);

Then, the field IntValue is set to 3.

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 396 10/31/2022
1.0.3 365 10/25/2022
1.0.2 393 10/24/2022
1.0.1 386 10/17/2022
1.0.0 391 8/3/2022