Pygmalions.Prism.Injecting 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Pygmalions.Prism.Injecting --version 1.0.3                
NuGet\Install-Package Pygmalions.Prism.Injecting -Version 1.0.3                
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.3" />                
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.3                
#r "nuget: Pygmalions.Prism.Injecting, 1.0.3"                
#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.3

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

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 392 10/31/2022
1.0.3 361 10/25/2022
1.0.2 389 10/24/2022
1.0.1 382 10/17/2022
1.0.0 387 8/3/2022