Extensible 0.3.0

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

// Install Extensible as a Cake Tool
#tool nuget:?package=Extensible&version=0.3.0                

Extensible

This package is heavily inpired by the extensibility patterns outlined in Miguel Castro's excellent Pluralsight Course AND the Extensibility work done on csharpfritz' CoreWiki project and aims to slightly reduce the boilerplate code required project to project... yes, i'm incredibly lazy!

Extensible is compatible with .NET Framework versions 3.5, 4.0 and 4.5 while currently there is only support for .NET Standard 2.0 (Happilly accept help to get 1.0 running)

Installation

PM> Install-Package Extensible

Example usage

With simple Events class

public class ExampleEvents
{
    public Action<OnMessageReceivedEventArgs> OnMessageReceived { get; set; }
}

public class OnMessageReceivedEventArgs : CancelEventArgs
{
    public string Message { get; set; }

    public OnMessageReceivedEventArgs(string message)
    {
        Message = message;
    }
}

And a simple Host class where we extend the ModuleHost<T> base class

public class ExampleEventsHost : ModuleHost<ExampleEvents>
{
    public ExampleEventsHost(string path, ExampleEvents events) : base(new DirectoryLoader<ExampleEvents>(path), events)
    {
    }

    public void InvokeOnMessageReceived(OnMessageReceivedEventArgs args)
    {
        try
        {
            if(Events.OnMessageReceived != null)
            {
                InvokeCancelableModuleEvent(Events.OnMessageReceived, args);
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine($"InvokeOnMessageReceived({args.Message}) threw an exception with message: {ex.Message}");
        }
    }
}

We can easily create an instance of this Host an Invoke events. Any modules loaded by the DirectoryLoader will be invoked.

var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName, "Modules");
var events = new ExampleEvents();
var host = new ExampleEventsHost(path, events);

var onReceivedEventArgs = new OnMessageReceivedEventArgs("Some text...");
host.InvokeOnMessageReceived(onReceivedEventArgs);

Loaders

Loaders allow Extensible to discover 'Modules' that can hook into extensibility events.

DirectoryLoader

The Director loader will scan a directory for Modules implementing the IModule<T> interface. This can be used to create a plugin style architecture where the types to be loader are not known ahead of time.

ReferenceLoader

The Reference loader will scan the current assemly and any referenced assemblies for Modules implmenting the IModule<T> interface.

TypeLoader

The Type loader will load and initialize an array of specific types that implement the IModule<T> interface. I use this to specify modules in config to use with DI.

Modules

Here is a very basic example of a Module

public class ArchiveModule : IModule<ExampleEvents>
{
    public void Initialize(ExampleEvents events)
    {
        events.OnMessageCreated += (e) => Console.WriteLine($" => [ArchiveModule] Message created: Id={e.Message.Id}, MessageText={e.Message.MessageText}");
    }
}

A full working example can be seen in the examples directory.

Contributing

Happy to accept ideas, suggestions and pull requests 😃

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 net35 is compatible.  net40 is compatible.  net403 was computed.  net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  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.
  • .NETFramework 3.5

    • No dependencies.
  • .NETFramework 4.0

    • No dependencies.
  • .NETFramework 4.5

    • No dependencies.
  • .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.3.0 640 6/24/2019