Confinity Documentation
  • Latest Version
  • Latest Version
  • Getting Started

    • Introduction
    • Core Concepts
    • Create an Application
    • Glossary
  • Essentials

    • Authentication & SSO
    • Breaking Changes
    • Roslyn Source Analyzers
    • Changelog
    • ConfinityContent
    • ConfinitySelectable
    • Confinity Schedules
    • Data Seeding
    • Development guidelines [WIP]
    • Entity App
    • Entity Form
    • Entity Permissions
    • Frontend Configuration
    • Images
    • Known Issues
    • Localization
    • Migrations
    • Modules [WIP]
    • On-Site Editing
    • Settings
    • Cascade Delete
    • Replication
    • Infrastructure
  • Modules

    • Analytics Module
    • Assets Module
    • Blog Module
    • Cookie Consent Module
    • Forms Module
    • Friendly Captcha (Forms Module )
    • GeoIP Module
    • Htmx
    • Mail Module
    • Mailing Module
    • MediaPlayer Module
    • GoogleMyBusiness Module
    • OpenTelemetry Module
    • Pages Module [WIP]
    • Pattern Library Module
    • SIX Saferpay (worldline) Module
    • Products Module
    • Search Module
    • Wizard Module
  • Guides

    • Create a Custom Entity App Form Element
    • Date and Time
    • Entity Change Listener
    • File Upload / Temp File
    • HTTP security headers
    • conventions [WIP]
    • How to use Confinity with nginx
    • Notifications
    • Nullability
    • Rename Entity
    • Schedules
    • Useful snippets
    • Content Localization
  • Design Guidelines

    • Introduction
    • Page Components
    • Forms Module

Modules [WIP]

A module is a package of functionality to extend Confinity. It can consist of:

  • Confinity Apps
  • ConfinityContent
  • Entities
  • Page templates
  • Page components
  • Static resources (JS, CSS, ...)
  • Views
  • Controllers
  • and so on...

In most cases, the host application itself is registered as a module, to add one or multiple features as mentioned above.

List of Modules

Confinity already contains a few modules out of the box. For a complete list search for Confinity. in the nuget repository.

NameDescriptionNuGet Package Name
BlogAdds functionality which allows you to write blog article and publish them on your page.Confinity.Blog
FormsAllows you to build custom forms for your website.Confinity.Forms
MailAllows you to send emails using Razor ViewsConfinity.Mail
MediaPlayerAllows you to include videos and audio files on your website.Confinity.MediaPlayer

Using an Existing Module

To include an existing module you have to add the NuGet package and then register the module in your Confinity service registration.

Let's add the Forms module by executing the following command, to add the Forms NuGet package.

dotnet add package Confinity.Forms

In your Startup.cs you can now register the module with the module builder by calling the AddModule method like this:


var builder = WebApplication.CreateBuilder(args);

var confinityOptions = new ConfinityOptions(new SqliteDatabaseProviderConfiguration());
builder.Services.AddConfinity(builder, confinityOptions, moduleBuilder =>
{
    moduleBuilder.AddModule<FormsModule>();
});

Might Require Database Migration

When you already have an existing database and a module, like the Forms module, adds new entities, you have to migrate your database.

Read here how to migrate your database.

That's it. You can now run your application and you'll see the Forms app in your menu.

Create a Module

You can create a new module by creating a class which implements the IModuleConfiguration interface.


public class MyModule : IModuleConfiguration
{
    public string ModuleKey { get; } = "my-module";

    public void AddModule(IModuleContext module)
    {
    }

    public void UseModule(IApplicationBuilder app)
    {
    }
}

In the AddModule you can register services, configure ConfinityContent types, add new Entity Apps, and so on.

Add static files

Your module can contain static files (javascript / images / css / etc.). Confinity does prefix your module static assets to prevent collisions. The path is configurable but defaults to /.mod/<module-key>/static/<your file>.

The files are served from the embedded manifest. Therefore your project needs to specify the following in your csproj file.

  • Add Microsoft.Extensions.FileProviders.Embedded reference.
  • In ProjectGroup add <GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
  • Add a new ItemGroup with your embedded resources: <ItemGroup><EmbeddedResource Include="wwwroot/**/*" CopyToOutputDirectory="Never"/></ItemGroup>
  • Important is, that you explicit specify CopyToOutputDirectory="Never" otherwise .net does write your files in the wwwroot folder. This could cause issues (file conflicts and so on).

For details see Manifest Embedded File

Warning

this causes a conflict with aspnet internals. When embedding translations (.resx) add <ExcludeFromManifest>true</ExcludeFromManifest>. Example:

<ItemGroup>
    <EmbeddedResource Update="Resources\MyResources.resx">
        <Generator>PublicResXFileCodeGenerator</Generator>
        <LastGenOutput>MyResources.Designer.cs</LastGenOutput>
        <ExcludeFromManifest>true</ExcludeFromManifest>
    </EmbeddedResource>
</ItemGroup>

Generate URLs for your static files

To get valid urls pointing to your files, use the IStaticResourceHelper.CreateUrlForStaticResource method.

Prev
Migrations
Next
On-Site Editing