Modules

What is a module ?

A module is a component that allows you to extend capabilities of your website. It may be a view component or a web API for the website. A module can be installed/uninstalled with the administration panel.

In order to create a module, you must create a C# library project that implements the Kastra.Core library.

How to declare a module ?

You need to add a class which derives from ModuleBase class available in the Kastra.Core namespace. The install method of the ModuleBase class will install automatically the module data in your website. These data must be in a fil named moduleconfig.json.

An example could be :

ArticleModule.cs


public class ArticleModule : ModuleBase
{
    public override void SetDependencyInjections(IServiceCollection services, IConfiguration configuration)
    {
        // Add services or dependancy injections
    }

    public override void Install(IServiceProvider serviceProvider, IViewManager viewManager)
    {
        base.Install(serviceProvider, viewManager);

         // Add your specific code to install your module
    }

    public override void Uninstall()
    {
        // Add your specific code to uninstall your module
    }
}

moduleconfig.json


{
	"Modules": [{
		"Definition": {
			"SystemName": "Article",
			"DisplayName": "Article",
			"Namespace": "Kastra.Module.Article",
			"Path": "Default/Article",
			"Version": "1.0"
		},
		"Controls": [{
				"KeyName": "Settings",
				"Path": "Settings"
			},
			{
				"KeyName": "Edit",
				"Path": "Edit"
			}
		]
	}]
}