Pygmalions.Nebula.Proxying
0.1.1
dotnet add package Pygmalions.Nebula.Proxying --version 0.1.1
NuGet\Install-Package Pygmalions.Nebula.Proxying -Version 0.1.1
<PackageReference Include="Pygmalions.Nebula.Proxying" Version="0.1.1" />
paket add Pygmalions.Nebula.Proxying --version 0.1.1
#r "nuget: Pygmalions.Nebula.Proxying, 0.1.1"
// Install Pygmalions.Nebula.Proxying as a Cake Addin #addin nuget:?package=Pygmalions.Nebula.Proxying&version=0.1.1 // Install Pygmalions.Nebula.Proxying as a Cake Tool #tool nuget:?package=Pygmalions.Nebula.Proxying&version=0.1.1
Nebula Proxying
Fundamental library of Pygmalions' Nebula Framework.
This library provides proxy interfaces, a proxy class generator and aspect handler mechanism.
Concepts
Proxy Class
A proxy class is the class type generated by proxy generator, which overrides virtual methods marked with Proxy attribute.
When those generated method are invoked, they will firstly trigger the Invoking event, then invoke the Invoker action delegate, which will invoke the proxied method by default, and finally trigger the Triggered event.
Aspect Handler
The generator will generate a ProxyEntry for each proxied method, when these proxy entries are initialized in the constructor, the generator will pass them to the registered aspect handlers. And then, the aspect handlers can add event subscribers to the proxy entry, or change the invoker of it, in order to dynamically change the behavior of the proxy method.
The proxy entry will be passed the aspect handlers of the corresponding aspects marked on the proxied method.
An aspect is a attribute class inherited from AspectTrigger class. You can declare aspects in the [AspectHandler] attribute marked on aspect handler classes. Then, proxy entries which has a the corresponding aspect attribute marked on its proxied method will be passed to this aspect handler.
How to Use
Proxy
This code shows how to get the arguments and returning value of an invocation on the proxy method:
var refraction = Proxies.Get<SampleObject>();
var testSample = Activator.CreateInstance(refraction) as SampleObject;
var provider = testSample as IProxyObject;
var proxy = provider!.GetProxy(typeof(SampleObject).GetMethod(nameof(SampleObject.AddNumber))!);
bool invokingTriggered = false, invokedTriggered = false;
var argument = -1;
proxy!.Invoking += context =>
{
invokingTriggered = true;
if (context.Arguments[0] is int parameter)
argument = parameter;
context.Arguments[0] = 5;
};
var returningValue = -1;
proxy.Invoked += context =>
{
invokedTriggered = true;
if (context.Result is int value)
returningValue = value;
context.Return(10);
};
var initialNumber = testSample!.Number;
var result = testSample.AddNumber(3);
This is a sample aspect handler, which will record all proxy entries.
[AspectHandler(typeof(ProxyAttribute))]
public class SampleGeneratorPlugin : AspectHandler
{
public static List<ProxyEntry> GeneratedProxies { get; } = new();
public override void Handle(ProxyEntry proxy)
{
GeneratedProxies.Add(proxy);
}
}
Remarks
This library is under rapid development, thus its API may be very unstable, DO NOT use it in the production environment, until its version reaches 1.0.0.
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.Nebula.Extending (>= 0.2.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
This library under rapid development, thus its API may be unstable. It is not recommended to use this library in production until the version of this library reaches 1.0.0.