Pygmalions.Prism.Injecting
1.0.3
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
<PackageReference Include="Pygmalions.Prism.Injecting" Version="1.0.3" />
paket add Pygmalions.Prism.Injecting --version 1.0.3
#r "nuget: Pygmalions.Prism.Injecting, 1.0.3"
// 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 | Versions 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. |
-
net6.0
- Pygmalions.Prism.Framework (>= 1.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.