Modules are a type of Nucleus extension which add functionality to the user interface.
This walkthrough assumes that you have installed the Nucleus developer tools from the Downloads page.
Create a new project in Visual Studio 2022. In the Create a new project Visual Studio dialog, search for "nucleus" to find the Nucleus project templates. If you are creating an extension which writes data to module-specific database tables, select the Nucleus Complex Extension Project project template, which includes controllers, a data provider, view models, views and a manager class. If you are developing a simple module or other extension which uses built-in Nucleus tables to store module settings, use the Nucleus Simple Extension Project template, which does not include data provider and manager classes.
Enter your project name and the location for your source code files and click Create.
Your publisher information and the extension friendly name and description are automatically included in the manifest (package.xml) file, and are displayed during installation and in the extensions control panel. You can change this information later by editing package.xml.
Extension Namespace | The root namespace for classes in your generated code. |
Extension Name | The extension name is used as the folder name (in /extensions) for your installed extension, and is also used by MVC routing, so it is a good idea to make sure that it doesn't contain spaces, or any characters which can't be used by file systems or in Urls. |
Friendly Name | The friendly name is displayed when installing your extension, and in the Extensions control panel after your module is installed. |
Model Class Name | Class name used when generating code for the default model class, and in other classes which reference it. |
Description | The description is displayed when installing your extension, and in the Extensions control panel after your module is installed. |
Click Next. Your project is automatically generated and you are ready to start developing.
The templates reference version 1 of the Nucleus Nuget packages. If you want to use API methods which were introduced after version 1,
you should use the "Manage Nuget Packages" menu item in Visual Studio to update to the latest version. You will need to edit your package.xml
file <compatibility>
element to specify that your extension requires a minimum version of Nucleus (the version number will match the version
of the Nuget packages that you reference.) Refer to the documentation on extension packaging for more information.
Nucleus Extensions are .Net Core ASP.NET MVC projects which use a controller class which contains
actions (functions). Controller actions execute code to populate view model classes, which are passed to Razor views to generate output.
DataProviders/Migrations/Scripts
, and edit the 01.00.00.json
script. Migration scripts are in .json format, and are a (mostly)
database agnostic way to define your database objects. The Nucleus project template generates a commented-out example which you can modify to create your database table(s). The
main database table for most modules will include an Id column to serve as a unique key for each record, a Module Id column to link your data to a module instance, and
DateAdded, AddedBy, DateChanged and ChangedBy columns to provide simple tracking of changes to data. The other columns will be specific to your module. If your module
doesn't need its own database tables, you can use the Nucleus Simple Extension Project template, or you can just delete the DataProviders
folder. ModelBase
.DataProviders
folder. Most extensions use Entity Framework
to access the database. Add the methods your module needs to access data.Models\Settings.cs
to represent the settings, and add lines of code to the ReadSettings function to populate them from the ModuleSettings class. In
the pattern which is implemented by the template, the Settings and Viewer view model classes inherit the settings class. using System;
using Nucleus.Abstractions.Managers;
using Nucleus.Abstractions.Models.Cache;
using Nucleus.Modules.Documents.Models;
namespace Nucleus.Modules.Documents
{
public static class CacheExtensions
{
public static CacheCollection<Guid, Document> DocumentCache (this ICacheManager cacheManager)
{
return cacheManager.Get<Guid, Document>();
}
}
}
.Get
Data Provider method in a call to the data caching system. If you are not implementing data caching, you
can remove the lines of code which call the Nucleus Cache Manager.ModuleSettings
collection. More complex settings may use your Manager class to
store data in your module's database tables. [Authorize(Policy = Nucleus.Abstractions.Authorization.Constants.MODULE_EDIT_POLICY)]
ModuleSettings
collection into your view model, but more complex settings may use your Manager class to read data from your module's database tables. Viewer
controller actions may also have an Authorize attribute to control access, if required. @model Nucleus.Extensions.GoogleAnalytics.ViewModels.Settings
@addTagHelper "*, Nucleus.ViewFeatures"
@using Nucleus.ViewFeatures.HtmlHelpers
@using Nucleus.ViewFeatures
@using Nucleus.Abstractions.Models
@Html.AddStyle("~!/../settings.css")
<div class="nucleus-editor-panel">
<h2 class="nucleus-control-panel-heading">Google Analytics Settings</h2>
@using (Html.BeginNucleusForm("Settings", "GoogleAnalytics", FormMethod.Post, new { @enctype = "multipart/form-data" }))
{
<fieldset role="group" aria-labelledby="heading">
<h2 class="nucleus-control-panel-heading">Settings</h2>
<div class="nucleus-flex-fields">
<SettingsControl caption="Google Analytics ID" helptext="Enter the Google Analytics ID for your site. You can disable Google Analytics by setting a blank value.">
@Html.TextBoxFor(model => model.GoogleAnalyticsId)
</SettingsControl>
</div>
<div class="nucleus-form-buttonrow">
@Html.SubmitButton("", "Save Settings", @Url.NucleusAction("SaveSettings", "GoogleAnalytics", "GoogleAnalytics"), new { })
</div>
</fieldset>
}
</div>
<folder>
and <file>
entries for any views or static resources (css, images) that you have added. If your project includes a readme
and/or license file, add <file>
entries at the root level for them. Files named readme.txt, readme.md, readme, readme.htm, license.txt, license.md, license
or license.htm
are automatically displayed to end users during installation. .csproj
) file.In Release configuration, the Nucleus build script creates an installation package. In Debug configuration, the Nucleus build script copies the package files to
%NUCLEUS_PATH%\Extensions\{extension-name}\
. When debugging, you will need to install a release build first so that any required database entries are created, but after the first installation you can generally just do a debug build to update the files in your Nucleus test instance.
You can debug by downloading and running the Nucleus source code from GitHub in Visual Studio, or if you are running a compiled version, you can use the Debug/Attach to Process function in Visual Studio to attach to a running instance. If you run
Nucleus.Web.exe
directly, you can attach to the process namedNucleus.Web.exe
. If you are running from Internet Information Services, you will attach tow3wp.exe
.
%NUCLEUS_PATH%
is automatically set to the location of the Nucleus build tools the first time you create a project, but your Nucleus test instance won't be located there, so once you have installed a test instance on your local machine, you will need to edit theNUCLEUS_PATH
environment variable and point it at your test instance. You will also need to copymodule.build.targets
from GitHub to your new%NUCLEUS_PATH%
.