Plugins.

Plugins allow to customize and extend Component functionality without source code modification. For example, one developer can implement CustomerForm component and other developer can add fields to that form from outside. So generally plugins are useful for customization.

Creating plugins

To create new plugin it is enought to create new class and implement IPlugin marker interface

Plugin interface
  1. public interface IPlugin<TContainer, TPlugin> : IContract<TContainer, TPlugin>
  2.   where TContainer : Component
  3. {
  4.   bool IsInitialized { get;}
  5.   bool IsDestroyed { get;}
  6.   void Initialize();
  7.   void Destroy();
  8. }

Typically it is prefferable to derive plugins from Component, in this case plugin would look as simple as that:

Plugin sample
  1. public class MyForm : Form
  2. {
  3. }
  4.  
  5. public class MyFormPlugin : Component, IPlugin<MyForm, MyFormPlugin>
  6. {
  7.   private MyForm myForm;
  8.   
  9.   public MyFormPlugin(MyForm myForm)
  10.   {
  11.     this.myForm = myForm;
  12.   }
  13.  
  14.   public override void OnInitializing()
  15.   {
  16.     base.OnInitializing();
  17.     myForm.Fields.Add(new TextField {Label = "Custom field"});
  18.   }
  19. }

Plugins are automatically created and initialized when Component initializes.

Registering and accessing plugins

Plugins are based on LiveUI Contracts so they should be registered and accessed absolutely the same way. See contracts for details