{"id":19848639,"url":"https://github.com/polterguy/magic.signals","last_synced_at":"2025-05-01T22:30:34.417Z","repository":{"id":45271229,"uuid":"209470640","full_name":"polterguy/magic.signals","owner":"polterguy","description":"A dynamic function invocation library for .Net Core","archived":false,"fork":false,"pushed_at":"2024-01-22T09:21:33.000Z","size":264,"stargazers_count":2,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-06T18:50:35.603Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://ainiro.io","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/polterguy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-19T05:37:35.000Z","updated_at":"2023-04-13T17:46:14.000Z","dependencies_parsed_at":"2023-12-19T16:06:51.933Z","dependency_job_id":"363c0e7f-5201-4845-b4b1-b86144b80885","html_url":"https://github.com/polterguy/magic.signals","commit_stats":null,"previous_names":[],"tags_count":74,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polterguy%2Fmagic.signals","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polterguy%2Fmagic.signals/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polterguy%2Fmagic.signals/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polterguy%2Fmagic.signals/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polterguy","download_url":"https://codeload.github.com/polterguy/magic.signals/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251954672,"owners_count":21670847,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T13:17:52.330Z","updated_at":"2025-05-01T22:30:34.106Z","avatar_url":"https://github.com/polterguy.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# magic.signals - Super signals for Hyperlambda\n\nmagic.signals is a _\"Super Signals\"_ implementation for .Net 8 built on top of magic.node,\nallowing you to invoke functions from one assembly in another assembly without having any direct references between\nyour projects.\n\n## Active Events or Super Signals internals\n\nZero cross project references is made possible by always having a YALOA, allowing us to invoke methods in classes through\na _\"magic string\"_, which references a type in a dictionary, where the string is its key, and the types\nare dynamically loaded during startup of your AppDomain. Imagine the following code.\n\n```csharp\n[Slot(Name = \"foo.bar\")]\npublic class FooBar : ISlot\n{\n    public void Signal(ISignaler signaler, Node input)\n    {\n        input.Value = 42;\n    }\n}\n```\n\nThe above declares a _\"slot\"_ for the signal **[foo.bar]**. In any other place in our AppDomain we can use an `ISignaler`\ninstance to Signal the above slot by using something such as the following.\n\n```csharp\n/*\n * This will invoke our Signal method above\n */\nvar args = new Node();\nsignaler.Signal(\"foo.bar\", args);\n\n/*\n * The value of args is now 42.\n */\nAssert.Equal(42, args.Value);\n```\n\nNotice that there are no shared types between the invoker and the handler, and there are no references necessary to\nbe shared between these two assemblies. This results in an extremely loosely coupled plugin architecture, where you can\ndynamically add any plugin you wish into your AppDomain, by simply referencing whatever plugin assembly you\nwish to bring into your AppDomain, and immediately start consuming your plugin's functionality - Or dynamically loading\nit during runtime for that matter, resulting in that you instantly have access to its slots, without needing to create\ncross projects references in any ways.\n\nThis results in an extremely loosely coupled architecture of related components, where any one component can easily be\nexchanged with any other component, as long as it is obeying by the implicit interface of the component you're replacing.\nCompletely eliminating _\"strongly typing\"_, making interchanging components with other components equally simply in a\nstatic programming language such as the .Net CLR as providing a function object in JavaScript.\n\nIn many ways, this\nresults in having all the advantages from a functional programming language in a static programming language, while still\nkeeping the strongly typing around for cases where you need strongly typing - Allowing you to choose which paradigm you\nwant to use, based upon individual use cases, and not having the language and platform dictate your choices in these\nregards.\n\nThe magic.signals implementation uses `IServiceProvider` to instantiate your above `FooBar` class when it\nwants to evaluate your slot. This makes it behave as a good IoC citizen, allowing you to pass in for instance\ninterfaces into your constructor, and have the .Net dependency injection automatically create objects\nof whatever interface your slot implementation requires.\n\nThere is also an `async` version of the interface, which allows you to declare async slots, transparently\nletting the runtime choose which implementation to use, depending upon whether or not it is currently in\nan `async` execution context or not. Below you can see how to accomplish the same as above, except this\ntime the slot will be invoked within an `async` context.\n\n```csharp\n[Slot(Name = \"foo.bar\")]\npublic class FooBar : ISlotAsync\n{\n    public Task SignalAsync(ISignaler signaler, Node input)\n    {\n        input.Value = 42;\n        await Task.Yield();\n    }\n}\n```\n\nIt's a common practice to implements slots that recursively invokes other slots, by combining the above two constructs, into\none single class. Below is an example.\n\n```csharp\n[Slot(Name = \"foo.bar\")]\npublic class FooBar : ISlot, ISlotAsync\n{\n    // Sync version.\n    public void Signal(ISignaler signaler, Node input)\n    {\n        input.Value = 42;\n    }\n\n    // Async version.\n    public async Task SignalAsync(ISignaler signaler, Node input)\n    {\n        input.Value = 42;\n        await Task.Yield();\n    }\n}\n```\n\nThe above simple example is probably not that useful to implement as an `async` slot, but for other parts of your code,\nwhere you for instance are accessing sockets, HTTP connections, or the file system for that matter - Creating\nasync slots will have huge advantages for your application's ability to scale, and handle multiple simultaneous\nusers and connections. The runtime will _\"automagically\"_ choose the correct implementation, being synchronous or\nasynchronous, depending upon which execution context the execution object currently is within.\n\nIf your slots recursively invokes other slots, by for instance invoking `signaler.Signal(\"eval\", args)`, you should\nalso implement the `async` interface, to allow for children lambda objects to be within an async context. This has huge\nadvantages for your application's throughput.\n\n## Passing arguments to your slots\n\nThe Node class provides a graph object for you, allowing you to automagically pass in any arguments you wish.\nNotice, the whole idea is to de-couple your assemblies, hence you shouldn't really pass in anything but native types,\nsuch as for instance `System.String`, `System.DateTime`, integers, etc. However, most complex POD structures, can also\neasily be represented using this `Node` class.\n\nThe Node class is basically a name/value/children graph object, where\nthe value can be any object, the name a string, and children is a list of children Nodes. In such a way, it provides\na more C# friendly graph object, kind of resembling JSON, allowing you to internally within your assemblies, pass\nin a Node object as your parameters from the point of your signal, to the slot where you handle the signal.\n\nThe `Node` POCO class again, is a bi-directional POD instance, allowing you to both pass arguments _into_ the\nslot, in addition to having the slot _return_ values back to the caller.\n\nIf you invoke `Signal` or `SignalAsync` from C#, you can optionally pass in a function object that will\nbe executed after the signal has been executed. This is useful for cases where you're creating an async signal\ninvocation, but not invoking it immediately, and rather returning it as a `Task` to some other parts of your\nsystem, to ensure something occurs _after_ the signal has been executed. Below is an example.\n\n```csharp\nvar args = new Node();\nreturn signaler.SignalAsync(\"foo.bar\", args, () =\u003e { /* ... This will happen AFTER execution of signal ... */ });\n\n```\n\n## Magic Signals a DSL\n\nA lot of the idea behind Magic Signals is that combined with magic.node,\nand especially its ability to parse Hyperlambda, it becomes a very good foundation for a DSL, or a Domain Specific\nprogramming Language implementation, allowing you to easily create your own programming languages, and keywords,\nbased upon Hyperlambda syntax trees. Hyperlambda in this context being the textual representation of your `Node`\nhierarchy.\n\n## Magic's GitHub project page\n\nMagic is 100% Open Source and you can find the primary project GitHub page [here](https://github.com/polterguy/magic).\n\n## Project website for magic.signals\n\nThe source code for this repository can be found at [github.com/polterguy/magic.signals](https://github.com/polterguy/magic.signals), and you can provide feedback, provide bug reports, etc at the same place.\n\n- ![Build status](https://github.com/polterguy/magic.signals/actions/workflows/build.yaml/badge.svg)\n- [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=polterguy_magic.signals\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=polterguy_magic.signals)\n- [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=polterguy_magic.signals\u0026metric=bugs)](https://sonarcloud.io/dashboard?id=polterguy_magic.signals)\n- [![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=polterguy_magic.signals\u0026metric=code_smells)](https://sonarcloud.io/dashboard?id=polterguy_magic.signals)\n- [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=polterguy_magic.signals\u0026metric=coverage)](https://sonarcloud.io/dashboard?id=polterguy_magic.signals)\n- [![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=polterguy_magic.signals\u0026metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=polterguy_magic.signals)\n- [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=polterguy_magic.signals\u0026metric=ncloc)](https://sonarcloud.io/dashboard?id=polterguy_magic.signals)\n- [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=polterguy_magic.signals\u0026metric=sqale_rating)](https://sonarcloud.io/dashboard?id=polterguy_magic.signals)\n- [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=polterguy_magic.signals\u0026metric=reliability_rating)](https://sonarcloud.io/dashboard?id=polterguy_magic.signals)\n- [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=polterguy_magic.signals\u0026metric=security_rating)](https://sonarcloud.io/dashboard?id=polterguy_magic.signals)\n- [![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=polterguy_magic.signals\u0026metric=sqale_index)](https://sonarcloud.io/dashboard?id=polterguy_magic.signals)\n- [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=polterguy_magic.signals\u0026metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=polterguy_magic.signals)\n\n## Copyright and maintenance\n\nThe projects is copyright Thomas Hansen 2023 - 2024, and professionally maintained by [AINIRO.IO](https://ainiro.io).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolterguy%2Fmagic.signals","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolterguy%2Fmagic.signals","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolterguy%2Fmagic.signals/lists"}