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
- public
interface
IPlugin<TContainer, TPlugin> :
IContract<TContainer, TPlugin>
- where TContainer :
Component
- {
- bool IsInitialized {
get;}
- bool IsDestroyed {
get;}
- void Initialize();
- void Destroy();
- }
Typically it is prefferable to derive plugins from Component, in this case
plugin would look as simple as that:
Plugin sample
- public
class
MyForm :
Form
- {
- }
-
- public
class
MyFormPlugin :
Component,
IPlugin<MyForm,
MyFormPlugin>
- {
- private
MyForm myForm;
-
- public MyFormPlugin(MyForm
myForm)
- {
- this.myForm = myForm;
- }
-
- public
override
void OnInitializing()
- {
- base.OnInitializing();
- myForm.Fields.Add(new
TextField
{Label = "Custom
field"});
- }
- }
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
|