Team XSockets.NET

Export

The first thing you need to do is to create an interface for your module.

public interface IAwesome
{
    void DoStuff();
}

To export this interface you have two options.

  1. Decorate the interface with the Export attribute
  2. Register the interface by using the RegisterExport<T> method

Using the Export attribute is the recommended way since you cant control InstancePolicy and Rewritable options with RegisterExport<T>.

Decorating with the Export attribute

//using XSockets.Plugin.Framework.Attributes;

[Export(typeof(IAwesome))]
public interface IAwesome
{
    void DoStuff();
}

Register with the interface with RegisterExport<T>

Composable.RegisterExport<IAwesome>();

Export as singleton

By default exports are created with the Instance policy set to NewInstance, which of course means that every time you ask for the plugin you will get a new instance. If you instead set the Instance policy to be Shared there will only be one instance of the plugin (a singleton).

[Export(typeof(IAwesome), instancePolicy: InstancePolicy.Shared)]

Export as rewritable

This is very useful and in XSockets most of our exported plugins is re-writable. The re-writable option means that you have created a plugin that can have only a single instance, but you allow the default instance to be overwritten by someone else. This is how you can replace modules in XSockets when you want them to behave different than the original implementation.

[Export(typeof(IAwesome), rewritable: Rewritable.Yes, instancePolicy: InstancePolicy.Shared)]

results matching ""

    No results matching ""