Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

A module inherits from the abstract class Lynicon.Extensibility.Module.  Below is an example showing some of the code of the module Auditing which stores an audit record for changes made via the data API.

Code Block
languagec#
linenumberstrue
public class Auditing : Module
{

...

	public Func<Type, bool> ApplyToType { get; set; }
 

...

	public Auditing(params string[] dependentOn)

...

		: base("Auditing.Basic", dependentOn)

...

	{

...

		Collator.Instance.SetupType(typeof(Audit), new BasicCollator(), new BasicRepository());

...

		ApplyToType = t => true;

...

	}

...

	public Auditing(Func<Type, bool> applyToType, params string[] dependentOn)
		: this(dependentOn)

...

	{

...

		ApplyToType = applyToType;

...

	}
 

...

	public override bool Initialise()

...

	{

...

		EventHub.Instance.RegisterEventProcessor("Repository.Set",

...

 

...

ProcessSet, "Auditing.Basic", new OrderConstraint("Auditing.Basic", ConstraintType.ItemsAfter, "Caching"));

...

		return true;

...

	}
 

...

	public void Deactivate()

...

	{

...

		EventHub.Instance.DeregisterEventProcessor("Repository.Set", "Auditing.Basic");

...

	}
 

...

	public object ProcessSet(EventHubData ehd)

...

	{

...

		var data = ((RepositoryEventData)ehd.Data).Container;

...

 
		... store if necessary ...

...

 
		return ehd.Data;

...

	}
}

The core code of the module is a series of methods which are called at different times by the LyniconModuleManager.When the module is constructed, we cannot rely on any of the Lynicon infrastructure being in place.  We can register content types needed by the module here and initialise the data of the module itself.  Notice that the simplest constructor calls the base constructor in Module supplying the name of the module.  After this, the Name property is set correctly and can be used whereever the module's name is required.In Initialise, we do the bulk of the initialisation work.  We can register events, define/customise the UI.  Initialise should return true to indicate the process was successful, or false to indicate a properly handled reason why the module could not start.RegisterRoutes is a method not shown here.  We override this to register any routes we need, an AreaRegistrationContext is passed in that lets us do this.Deactivate should be implemented for completeness to allow for the module to be deactivated at runtime.  In here, we deregister any events registered in Initialise.Finally the ProcessEvent method is a method with the right signature for an event handler for global events.