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.
| Name | Description | NuGet Package Name |
|---|---|---|
| Blog | Adds functionality which allows you to write blog article and publish them on your page. | Confinity.Blog |
| Forms | Allows you to build custom forms for your website. | Confinity.Forms |
| Allows you to send emails using Razor Views | Confinity.Mail | |
| MediaPlayer | Allows 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.
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.