### Install Weikio.PluginFramework.AspNetCore NuGet package Source: https://github.com/weikio/pluginframework/blob/master/README.md Install the Weikio.PluginFramework.AspNetCore NuGet package into an ASP.NET Core project. ```powershell Install-Package Weikio.PluginFramework.AspNetCore ``` -------------------------------- ### Delegate example with custom type parameter Source: https://github.com/weikio/pluginframework/wiki/Delegate-Plugin-Catalog A sample delegate from the documentation that uses an ExternalService parameter, intended to be used with conversion rules. ```csharp var funcWithExternalService = new Func((s, service) => { var words = service.GetWords(); s = s + Environment.NewLine + words; return s; }); ``` -------------------------------- ### Creating a DelegatePluginCatalog with a Func Source: https://github.com/weikio/pluginframework/wiki/Delegate-Plugin-Catalog An example of a Func-based plugin. The delegate takes an int and returns a Task, with a delay and console output before returning true. ```csharp var catalog = new DelegatePluginCatalog(new Func>(async i => { await Task.Delay(TimeSpan.FromMilliseconds(100)); Console.WriteLine("Hello from plugin"); return true; })); ``` -------------------------------- ### Inject plugins into controller constructor Source: https://github.com/weikio/pluginframework/blob/master/README.md Constructor injection example for a controller that receives all discovered IOperator plugins. ```csharp public CalculatorController(IEnumerable operator) { _operators = operators; } ``` -------------------------------- ### DelegateConversionRule examples for constructor and property conversion Source: https://github.com/weikio/pluginframework/wiki/Delegate-Plugin-Catalog Rules move parameters of type ExternalService to constructor parameters and parameters named 's' to public properties. Each rule uses a delegate for matching and a ParameterConversion object to specify the conversion target. ```csharp new DelegateConversionRule(info => info.ParameterType == typeof(ExternalService), nfo => new ParameterConversion() { ToConstructor = true }), new DelegateConversionRule(info => info.Name == "s", nfo => new ParameterConversion() { ToPublicProperty = true }), ``` -------------------------------- ### Script returning a Task Source: https://github.com/weikio/pluginframework/wiki/Roslyn-Plugin-Catalog Example of a C# script that returns a string. By default, scripts return a Task, so this code returns a Task. ```csharp var code = "var x = \"hello\"; return x;"; ``` -------------------------------- ### Creating, initializing, and executing a plugin instance Source: https://github.com/weikio/pluginframework/wiki/Delegate-Plugin-Catalog After creating and initializing the catalog, retrieve the plugin definition, create an instance dynamically, and invoke the Run method. ```csharp var catalog = new DelegatePluginCatalog(new Action(() => { Console.WriteLine("Hello from plugin"); })); await catalog.Initialize(); var ourPlugin = catalog.Single(); dynamic instance = Activator.CreateInstance(ourPlugin); instance.Run(); ``` -------------------------------- ### Creating a DelegatePluginCatalog with an Action Source: https://github.com/weikio/pluginframework/wiki/Delegate-Plugin-Catalog Define a plugin using an Action delegate. The catalog is initialized asynchronously and the Action executes when the plugin's Run method is invoked. ```csharp var catalog = new DelegatePluginCatalog(new Action(() => { Console.WriteLine("Hello from plugin"); })); await catalog.Initialize(); ``` -------------------------------- ### Register plugin framework with AddPluginFramework Source: https://github.com/weikio/pluginframework/blob/master/README.md Registers the plugin framework in ConfigureServices, scanning the myplugins folder for types implementing IOperator. ```csharp services.AddPluginFramework(@".\myplugins"); ``` -------------------------------- ### Configure multiple plugin catalogs with AddPluginFramework Source: https://github.com/weikio/pluginframework/blob/master/README.md Configures multiple plugin catalogs (FolderPluginCatalog) and registers them with AddPluginFramework, specifying the plugin type IOperator. ```csharp var folderPluginCatalog = new FolderPluginCatalog(@".\myplugins", type => { type.Implements(); }); var anotherPluginCatalog = new FolderPluginCatalog(@".\morePlugins", type => { type.Implements(); }); services.AddPluginFramework() .AddPluginCatalog(folderPluginCatalog) .AddPluginCatalog(anotherPluginCatalog) .AddPluginType(); ``` -------------------------------- ### Create RoslynPluginCatalog with a C# script Source: https://github.com/weikio/pluginframework/wiki/Roslyn-Plugin-Catalog Creates a RoslynPluginCatalog using a C# script string. The script is wrapped in a generated type and method, and by default returns a Task. ```csharp var script = "var x = \"Hello from Roslyn Plugin\"; return x;"; var roslynScriptCatalog = new RoslynPluginCatalog(script); ``` -------------------------------- ### Create RoslynPluginCatalog with full C# code Source: https://github.com/weikio/pluginframework/wiki/Roslyn-Plugin-Catalog Creates a RoslynPluginCatalog using a full C# class definition. The code is compiled as a plugin. ```csharp var code = @"public class MyClass { public void RunThings() { var y = 0; var a = 1; a = y + 10; Debug.WriteLine(y + a); } }"; var roslynCatalog = new RoslynPluginCatalog(script); ``` -------------------------------- ### Pass options to RoslynPluginCatalog Source: https://github.com/weikio/pluginframework/wiki/Roslyn-Plugin-Catalog Shows how to pass RoslynPluginCatalogOptions to the catalog constructor, setting the PluginName to 'MyPlugin'. ```csharp var options = new RoslynPluginCatalogOptions() { PluginName = "MyPlugin", }; var catalog = new RoslynPluginCatalog(code, options); ``` -------------------------------- ### Use additional references and namespaces Source: https://github.com/weikio/pluginframework/wiki/Roslyn-Plugin-Catalog Shows how to configure AdditionalReferences and AdditionalNamespaces in RoslynPluginCatalogOptions to provide extra assemblies and namespaces for the generated code. ```csharp var code = @"public class MyClass { private ExternalService _service; public MyClass(ExternalService service) { _service = service; } public string RunThings() { var result = JsonConvert.SerializeObject(15); result += _service.DoWork(); return result; } }"; var options = new RoslynPluginCatalogOptions() { PluginName = "MyPlugin", PluginVersion = new Version("1.5.0.0"), AdditionalReferences = new List() { typeof(Newtonsoft.Json.JsonConvert).Assembly, typeof(ExternalService).Assembly }, AdditionalNamespaces = new List() { "Newtonsoft.Json", "WebAppWithRoslyn" } }; var roslynCodeCatalog = new RoslynPluginCatalog(code, options); ``` -------------------------------- ### Default generated wrapper class for the delegate Source: https://github.com/weikio/pluginframework/wiki/Delegate-Plugin-Catalog By default, the generated class has no constructor parameters or properties. The Run method signature matches the delegate, and the body is omitted with ellipsis. ```csharp public class GeneratedType { public string Run(string s, ExternalService service) { ... } } ``` -------------------------------- ### Generated class with constructor parameter and public property Source: https://github.com/weikio/pluginframework/wiki/Delegate-Plugin-Catalog The resulting class after applying the conversion rules. The ExternalService becomes a constructor parameter stored in a private field, and the parameter 's' becomes a public property S. The Run method no longer takes these parameters. ```csharp public class GeneratedType { private ExternalService _service; public string S { get;set; } public GeneratedType(ExternalService service) { _service = service; } public string Run() { ... } } ``` -------------------------------- ### Generated Run method signature matching delegate Source: https://github.com/weikio/pluginframework/wiki/Delegate-Plugin-Catalog The generated Run method's signature matches the delegate's signature. For a Func taking int and bool and returning string, the method is public string Run(int x, bool y). ```csharp public string Run(int x, bool y) { ... return "result"; } ``` -------------------------------- ### Size SVG icons with CSS Source: https://github.com/weikio/pluginframework/blob/master/samples/BlazorApp/wwwroot/css/open-iconic/README.md Set equal width and height on the svg tag to size the square-format icons. ```css .icon { width: 16px; height: 16px; } ``` -------------------------------- ### Include Bootstrap icon font stylesheet Source: https://github.com/weikio/pluginframework/blob/master/samples/BlazorApp/wwwroot/css/open-iconic/README.md Link to the Bootstrap stylesheet for the Open Iconic icon font. The stylesheet is located in font/css/open-iconic-bootstrap.css. ```html ``` -------------------------------- ### Use an SVG sprite with use tag Source: https://github.com/weikio/pluginframework/blob/master/samples/BlazorApp/wwwroot/css/open-iconic/README.md Add an icon from the SVG sprite by referencing the sprite file and a unique class for each icon. Add a general class to the svg tag for easy styling. ```html ``` -------------------------------- ### Use Foundation icon font span Source: https://github.com/weikio/pluginframework/blob/master/samples/BlazorApp/wwwroot/css/open-iconic/README.md Use a span with the fi-icon-name class to display an icon with the Foundation font. ```html ``` -------------------------------- ### Include Foundation icon font stylesheet Source: https://github.com/weikio/pluginframework/blob/master/samples/BlazorApp/wwwroot/css/open-iconic/README.md Link to the Foundation stylesheet for the Open Iconic icon font. The stylesheet is located in font/css/open-iconic-foundation.css. ```html ``` -------------------------------- ### Use Bootstrap icon font span Source: https://github.com/weikio/pluginframework/blob/master/samples/BlazorApp/wwwroot/css/open-iconic/README.md Use a span with the oi class and an icon-specific class to display an icon with the Bootstrap font. ```html ``` -------------------------------- ### Include default icon font stylesheet Source: https://github.com/weikio/pluginframework/blob/master/samples/BlazorApp/wwwroot/css/open-iconic/README.md Link to the default stylesheet for the Open Iconic icon font. The stylesheet is located in font/css/open-iconic.css. ```html ``` -------------------------------- ### Use default icon font span Source: https://github.com/weikio/pluginframework/blob/master/samples/BlazorApp/wwwroot/css/open-iconic/README.md Use a span with the oi class and data-glyph attribute to display an icon with the default font. ```html ``` -------------------------------- ### Display an SVG icon with an img tag Source: https://github.com/weikio/pluginframework/blob/master/samples/BlazorApp/wwwroot/css/open-iconic/README.md Use this HTML snippet to display an Open Iconic SVG icon as a regular image. Remember to include the alt attribute for accessibility. ```html icon name ``` -------------------------------- ### Color SVG icons with CSS fill Source: https://github.com/weikio/pluginframework/blob/master/samples/BlazorApp/wwwroot/css/open-iconic/README.md Set the fill rule on the use tag to color the icon. ```css .icon-account-login { fill: #f00; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.