magic.signals
17.1.7
dotnet add package magic.signals --version 17.1.7
NuGet\Install-Package magic.signals -Version 17.1.7
<PackageReference Include="magic.signals" Version="17.1.7" />
paket add magic.signals --version 17.1.7
#r "nuget: magic.signals, 17.1.7"
// Install magic.signals as a Cake Addin #addin nuget:?package=magic.signals&version=17.1.7 // Install magic.signals as a Cake Tool #tool nuget:?package=magic.signals&version=17.1.7
magic.signals - Super signals for Hyperlambda
magic.signals is a "Super Signals" implementation for .Net 8 built on top of magic.node, allowing you to invoke functions from one assembly in another assembly without having any direct references between your projects.
Active Events or Super Signals internals
Zero cross project references is made possible by always having a YALOA, allowing us to invoke methods in classes through a "magic string", which references a type in a dictionary, where the string is its key, and the types are dynamically loaded during startup of your AppDomain. Imagine the following code.
[Slot(Name = "foo.bar")]
public class FooBar : ISlot
{
public void Signal(ISignaler signaler, Node input)
{
input.Value = 42;
}
}
The above declares a "slot" for the signal [foo.bar]. In any other place in our AppDomain we can use an ISignaler
instance to Signal the above slot by using something such as the following.
/*
* This will invoke our Signal method above
*/
var args = new Node();
signaler.Signal("foo.bar", args);
/*
* The value of args is now 42.
*/
Assert.Equal(42, args.Value);
Notice that there are no shared types between the invoker and the handler, and there are no references necessary to be shared between these two assemblies. This results in an extremely loosely coupled plugin architecture, where you can dynamically add any plugin you wish into your AppDomain, by simply referencing whatever plugin assembly you wish to bring into your AppDomain, and immediately start consuming your plugin's functionality - Or dynamically loading it during runtime for that matter, resulting in that you instantly have access to its slots, without needing to create cross projects references in any ways.
This results in an extremely loosely coupled architecture of related components, where any one component can easily be exchanged with any other component, as long as it is obeying by the implicit interface of the component you're replacing. Completely eliminating "strongly typing", making interchanging components with other components equally simply in a static programming language such as the .Net CLR as providing a function object in JavaScript.
In many ways, this results in having all the advantages from a functional programming language in a static programming language, while still keeping the strongly typing around for cases where you need strongly typing - Allowing you to choose which paradigm you want to use, based upon individual use cases, and not having the language and platform dictate your choices in these regards.
The magic.signals implementation uses IServiceProvider
to instantiate your above FooBar
class when it
wants to evaluate your slot. This makes it behave as a good IoC citizen, allowing you to pass in for instance
interfaces into your constructor, and have the .Net dependency injection automatically create objects
of whatever interface your slot implementation requires.
There is also an async
version of the interface, which allows you to declare async slots, transparently
letting the runtime choose which implementation to use, depending upon whether or not it is currently in
an async
execution context or not. Below you can see how to accomplish the same as above, except this
time the slot will be invoked within an async
context.
[Slot(Name = "foo.bar")]
public class FooBar : ISlotAsync
{
public Task SignalAsync(ISignaler signaler, Node input)
{
input.Value = 42;
await Task.Yield();
}
}
It's a common practice to implements slots that recursively invokes other slots, by combining the above two constructs, into one single class. Below is an example.
[Slot(Name = "foo.bar")]
public class FooBar : ISlot, ISlotAsync
{
// Sync version.
public void Signal(ISignaler signaler, Node input)
{
input.Value = 42;
}
// Async version.
public async Task SignalAsync(ISignaler signaler, Node input)
{
input.Value = 42;
await Task.Yield();
}
}
The above simple example is probably not that useful to implement as an async
slot, but for other parts of your code,
where you for instance are accessing sockets, HTTP connections, or the file system for that matter - Creating
async slots will have huge advantages for your application's ability to scale, and handle multiple simultaneous
users and connections. The runtime will "automagically" choose the correct implementation, being synchronous or
asynchronous, depending upon which execution context the execution object currently is within.
If your slots recursively invokes other slots, by for instance invoking signaler.Signal("eval", args)
, you should
also implement the async
interface, to allow for children lambda objects to be within an async context. This has huge
advantages for your application's throughput.
Passing arguments to your slots
The Node class provides a graph object for you, allowing you to automagically pass in any arguments you wish.
Notice, the whole idea is to de-couple your assemblies, hence you shouldn't really pass in anything but native types,
such as for instance System.String
, System.DateTime
, integers, etc. However, most complex POD structures, can also
easily be represented using this Node
class.
The Node class is basically a name/value/children graph object, where the value can be any object, the name a string, and children is a list of children Nodes. In such a way, it provides a more C# friendly graph object, kind of resembling JSON, allowing you to internally within your assemblies, pass in a Node object as your parameters from the point of your signal, to the slot where you handle the signal.
The Node
POCO class again, is a bi-directional POD instance, allowing you to both pass arguments into the
slot, in addition to having the slot return values back to the caller.
If you invoke Signal
or SignalAsync
from C#, you can optionally pass in a function object that will
be executed after the signal has been executed. This is useful for cases where you're creating an async signal
invocation, but not invoking it immediately, and rather returning it as a Task
to some other parts of your
system, to ensure something occurs after the signal has been executed. Below is an example.
var args = new Node();
return signaler.SignalAsync("foo.bar", args, () => { /* ... This will happen AFTER execution of signal ... */ });
Magic Signals a DSL
A lot of the idea behind Magic Signals is that combined with magic.node,
and especially its ability to parse Hyperlambda, it becomes a very good foundation for a DSL, or a Domain Specific
programming Language implementation, allowing you to easily create your own programming languages, and keywords,
based upon Hyperlambda syntax trees. Hyperlambda in this context being the textual representation of your Node
hierarchy.
Project website for magic.signals
The source code for this repository can be found at github.com/polterguy/magic.signals, and you can provide feedback, provide bug reports, etc at the same place.
Copyright and maintenance
The projects is copyright Thomas Hansen 2023 - 2024, and professionally maintained by AINIRO.IO.
Product | Versions 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. |
-
.NETStandard 2.0
- magic.node.extensions (>= 17.1.7)
- magic.signals.contracts (>= 17.1.7)
NuGet packages (5)
Showing the top 5 NuGet packages that depend on magic.signals:
Package | Downloads |
---|---|
magic.lambda
A microscopic and super dynamic scripting language and DSL for .Net Core, based upon Hyperlambda syntax, and Super Signals. This project is the Hyperlambda core implementation (keywords) for Magic. To use package go to https://polterguy.github.io |
|
magic.library
Helper project for Magic to wire up everything easily by simply adding one package, and invoking two simple methods. When using Magic, this is (probably) the only package you should actually add, since this package pulls in everything else you'll need automatically, and wires up everything sanely by default. To use package go to https://polterguy.github.io |
|
magic.lambda.threading
Threading support for Hyperlambda and Magic. To use package go to https://polterguy.github.io |
|
magic.lambda.cql
CQL data adapters for Magic and Hyperlambda. To use package go to https://polterguy.github.io |
|
magic.data.cql
CQL data adapters for Magic to store files and folders, etc. To use package go to https://polterguy.github.io |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
17.1.7 | 462 | 1/12/2024 |
17.1.6 | 395 | 1/11/2024 |
17.1.5 | 484 | 1/5/2024 |
17.0.1 | 498 | 1/1/2024 |
17.0.0 | 737 | 12/14/2023 |
16.11.5 | 778 | 11/12/2023 |
16.9.0 | 763 | 10/9/2023 |
16.7.0 | 1,099 | 7/11/2023 |
16.4.1 | 1,032 | 7/2/2023 |
16.4.0 | 973 | 6/22/2023 |
16.3.1 | 941 | 6/6/2023 |
16.3.0 | 950 | 5/28/2023 |
16.1.9 | 1,300 | 4/30/2023 |
15.10.11 | 1,128 | 4/13/2023 |
15.9.1 | 1,320 | 3/26/2023 |
15.9.0 | 1,235 | 3/24/2023 |
15.8.2 | 1,247 | 3/20/2023 |
15.7.0 | 1,194 | 3/6/2023 |
15.5.0 | 2,566 | 1/28/2023 |
15.2.0 | 1,842 | 1/18/2023 |
15.1.0 | 2,266 | 12/28/2022 |
14.5.7 | 1,815 | 12/13/2022 |
14.5.5 | 1,969 | 12/6/2022 |
14.5.1 | 1,914 | 11/23/2022 |
14.5.0 | 1,859 | 11/18/2022 |
14.4.5 | 2,188 | 10/22/2022 |
14.4.1 | 2,192 | 10/22/2022 |
14.4.0 | 2,077 | 10/17/2022 |
14.3.1 | 3,378 | 9/12/2022 |
14.3.0 | 2,090 | 9/10/2022 |
14.1.3 | 2,396 | 8/7/2022 |
14.1.2 | 2,177 | 8/7/2022 |
14.1.1 | 2,083 | 8/7/2022 |
14.0.14 | 2,162 | 7/26/2022 |
14.0.12 | 2,148 | 7/24/2022 |
14.0.11 | 2,135 | 7/23/2022 |
14.0.10 | 2,072 | 7/23/2022 |
14.0.9 | 2,090 | 7/23/2022 |
14.0.8 | 2,223 | 7/17/2022 |
14.0.5 | 2,318 | 7/11/2022 |
14.0.4 | 2,284 | 7/6/2022 |
14.0.3 | 2,243 | 7/2/2022 |
14.0.2 | 2,175 | 7/2/2022 |
14.0.0 | 2,355 | 6/25/2022 |
13.4.0 | 3,572 | 5/31/2022 |
13.3.4 | 2,884 | 5/9/2022 |
13.3.0 | 2,763 | 5/1/2022 |
13.2.0 | 2,731 | 4/21/2022 |
13.1.0 | 2,549 | 4/7/2022 |
13.0.0 | 2,217 | 4/5/2022 |
11.0.5 | 2,976 | 3/2/2022 |
11.0.4 | 2,315 | 2/22/2022 |
11.0.3 | 2,341 | 2/9/2022 |
11.0.2 | 2,332 | 2/6/2022 |
11.0.1 | 480 | 2/5/2022 |
11.0.0 | 2,292 | 2/5/2022 |
10.0.21 | 2,865 | 1/28/2022 |
10.0.20 | 2,290 | 1/27/2022 |
10.0.19 | 2,275 | 1/23/2022 |
10.0.18 | 1,733 | 1/17/2022 |
10.0.15 | 2,392 | 12/31/2021 |
10.0.14 | 1,233 | 12/28/2021 |
10.0.7 | 2,145 | 12/22/2021 |
10.0.5 | 1,338 | 12/18/2021 |
9.9.9 | 1,697 | 11/29/2021 |
9.9.3 | 1,878 | 11/9/2021 |
9.9.2 | 1,658 | 11/4/2021 |
9.9.0 | 1,939 | 10/30/2021 |
9.8.9 | 1,728 | 10/29/2021 |
9.8.7 | 1,682 | 10/27/2021 |
9.8.6 | 1,671 | 10/27/2021 |
9.8.5 | 1,732 | 10/26/2021 |
9.8.0 | 2,581 | 10/20/2021 |
9.7.9 | 542 | 10/19/2021 |
9.7.5 | 1,458 | 10/14/2021 |
9.7.0 | 843 | 10/9/2021 |
9.6.6 | 1,191 | 8/14/2021 |
9.2.0 | 6,257 | 5/26/2021 |
9.1.4 | 1,265 | 4/21/2021 |
9.1.0 | 1,035 | 4/14/2021 |
9.0.0 | 947 | 4/5/2021 |
8.9.9 | 1,218 | 3/30/2021 |
8.9.3 | 1,530 | 3/19/2021 |
8.9.2 | 1,021 | 1/29/2021 |
8.9.1 | 1,096 | 1/24/2021 |
8.9.0 | 1,206 | 1/22/2021 |
8.6.9 | 3,251 | 11/8/2020 |
8.6.6 | 1,963 | 11/2/2020 |
8.6.0 | 4,182 | 10/28/2020 |
8.5.0 | 2,060 | 10/23/2020 |
8.4.0 | 5,820 | 10/13/2020 |
8.3.1 | 2,733 | 10/5/2020 |
8.3.0 | 1,287 | 10/3/2020 |
8.2.2 | 2,047 | 9/26/2020 |
8.2.1 | 1,382 | 9/25/2020 |
8.2.0 | 1,328 | 9/25/2020 |
8.1.17 | 7,258 | 9/13/2020 |
8.1.16 | 666 | 9/13/2020 |
8.1.15 | 2,003 | 9/12/2020 |
8.1.11 | 2,578 | 9/11/2020 |
8.1.10 | 1,630 | 9/6/2020 |
8.1.9 | 1,532 | 9/3/2020 |
8.1.8 | 1,495 | 9/2/2020 |
8.1.7 | 1,201 | 8/28/2020 |
8.1.4 | 1,215 | 8/25/2020 |
8.1.3 | 1,284 | 8/18/2020 |
8.1.2 | 1,220 | 8/16/2020 |
8.1.1 | 1,267 | 8/15/2020 |
8.1.0 | 535 | 8/15/2020 |
8.0.1 | 2,698 | 8/7/2020 |
8.0.0 | 1,233 | 8/7/2020 |
7.0.1 | 493 | 8/7/2020 |
7.0.0 | 1,966 | 6/28/2020 |
5.0.0 | 7,606 | 2/25/2020 |
4.0.4 | 7,966 | 1/27/2020 |
4.0.3 | 1,272 | 1/27/2020 |
4.0.2 | 1,357 | 1/16/2020 |
4.0.1 | 1,372 | 1/11/2020 |
4.0.0 | 1,409 | 1/5/2020 |
3.1.0 | 6,422 | 11/10/2019 |
3.0.0 | 3,946 | 10/23/2019 |
2.0.1 | 8,247 | 10/15/2019 |
2.0.0 | 1,667 | 10/13/2019 |
1.2.0 | 1,401 | 10/11/2019 |
1.1.9 | 1,298 | 10/10/2019 |
1.1.8 | 627 | 10/10/2019 |
1.1.7 | 6,880 | 10/9/2019 |
1.1.6 | 3,461 | 10/7/2019 |
1.1.5 | 8,107 | 10/6/2019 |
1.1.3 | 6,559 | 10/6/2019 |
1.1.2 | 5,521 | 10/5/2019 |
1.1.1 | 548 | 10/5/2019 |
1.1.0 | 565 | 10/5/2019 |