Lilikoi 0.1.0-prerelease.28

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

// Install Lilikoi as a Cake Tool
#tool nuget:?package=Lilikoi&version=0.1.0-prerelease.28&prerelease

<center> <img src="https://raw.githubusercontent.com/Mooshua/Lilikoi/main/Assets/LilikoiBox1080.png" width="256"> <h1>Lilikoi</h1> </center>

Main main
Dev dev

[!WARNING] Lilikoi is in active, early development and should not be used unless you accept the risk that everything may change or break.

[!NOTE] Lilikoi requires the .NET 7 SDK in order to be compiled, but can be used (and is tested on) on any .NET Standard 2.0 platform.

Status

Feature Status
Field Injection ✔️
Parameter Injection ️️✔️
Hooks ("Wraps") ✔️
Contexts ("Mounts") ✔️
Builder Attributes ✔️
Configuration 🏗️
Headless/Portable 🏗️
Wildcards ✔️
Ecosystem
Async/Await
Debugging
NuGet Release ✔️

Documentation

Documentation is a work in progress, but here's what we have so far:

What is it?

Lilikoi is a framework for event handlers. It defines a common ground for dependency injection and pre/post behavior. This allows programmers to write framework agnostic code that runs anywhere Lilikoi runs.

Lilikoi consists of "Containers", which contain a class ("Host") and a method defined on that class (the "Entry Point"). Using C# reflection APIs, a method is created which injects values into an instance of the host class and then executes the entry point.

//  An attribute which injects a new SampleClass into the container
public class SampleInjectionAttribute : LkTypedInjectionAttribute<SampleClass>
{
	public override SampleClass Inject()
	{
		return new SampleClass();
	}
}
//  The host of the container
class Host
{
    [SampleInjection]
    private SampleClass _injectedClass;
  
    //  The entry point of the container
    public Task Entry()
    {
        _injectedClass.DoSomething();
    }
}

What is it good for?

Lilikoi acts as a glue layer between event producers and event handlers.

Lilikoi automates discovery of event handlers and creating an API surface that an event producer can easily consume. Lilikoi also generates the API surface expected by the handler at runtime--so both sides of the event handler can use the contracts they expect.

Lilikoi is used in my project BitMod, where it glues plugins together with event handlers:

public class WhitelistHooks
{
	[Config("whitelist")]
	private WhitelistFile _whitelist;

	[BitHook(Priority.LOW)]
	private async Task<Directive> ServerConnectionRequest(GameServerConnectingEventArgs ev)
	{
		foreach (IPAddress allowedConnection in _whitelist.Parse(_logger))
		{
			if (allowedConnection.GetAddressBytes().SequenceEqual(ev.IPAddress.GetAddressBytes()))
			    return Directive.Allow;
		}
		return Directive.Neutral;
	}
}

Other plugins and BitMod can then invoke these handlers with a gloriously simple API. The BitHook type places a RouterAssignments object in the container during compilation, which is consumed by BitMod to find containers that handle the same event and group them together. All in all, it looks like this:

public override async Task<bool> OnGameServerConnecting(IPAddress arg)
    => _invoker.Hook(new GameServerConnectingEventArgs(arg), defaultValue: false);

Overall, Lilikoi can be used in almost all event-handler use cases to provide consistent and understandable APIs to both the event producer and the consumer.

Headless

Like injecting things but don't want a full framework? Lilikoi's headless injectors build minimal Action<T>s which behave similarly to the full framework, giving you full control over the when and where.

Performance

Lilikoi is designed with performance in mind, so that projects of any scale can benefit from it's paradigms.

In order to maximize performance and prevent diving into .NET reflection, Lilikoi uses compiled expression trees, which behave just like a normal method.

Expression trees are no golden ticket to performanceville, but proper runtime code generation makes Lilikoi's overhead as low as 60ns per injection

Framework Task Speed
.NET CLR Inject 60 ns
.NET CLR Inject (Debug) 325 ns
.NET Framework Inject 100 ns
.NET CLR Compile 0.330 ms
.NET CLR Compile (Debug) 0.015 ms
.NET Framework Compile 0.460 ms
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.
  • .NETStandard 2.0

    • No dependencies.

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
0.1.0-prerelease.28 189 8/16/2023
0.1.0-prerelease.23 80 8/12/2023
0.1.0-prerelease.21 82 8/11/2023
0.1.0-prerelease.19 66 8/11/2023
0.1.0-prerelease.15 66 7/29/2023
0.1.0-prerelease.12 87 2/6/2023
0.0.50-prerelease.9 93 2/2/2023
0.0.50-prerelease.5 84 2/1/2023
0.0.49 265 2/1/2023
0.0.48 242 2/1/2023
0.0.47 245 2/1/2023
0.0.46 240 2/1/2023
0.0.45 244 2/1/2023
0.0.7-stable.55 85 2/1/2023
0.0.6-stable.54 86 2/1/2023