Skip to content

Latest commit

 

History

History
44 lines (31 loc) · 2.66 KB

File metadata and controls

44 lines (31 loc) · 2.66 KB

Lombiq Helpful Libraries - Orchard Core Libraries - Resource Management for Orchard Core

Resource Filter

Makes it possible to include resources automatically based on the current context, e.g. allows only injecting home page styling when the home page is being loaded.

Usage:

Activate the resource filter middleware by adding app.UseResourceFilters() to the Configure() method of the Startup file located in a common module or the web project:

public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
{
    app.UseResourceFilters();
}

To add resource filters, the IResourceFilterProvider interface needs to be implemented and the registration needs to be added to the service collection as well.

Example:

public class ResourceFilters : IResourceFilterProvider
{
    public void AddResourceFilter(ResourceFilterBuilder builder)
    {
        builder.WhenHomePage().RegisterHeadScript("HomePageStyle");
        builder.WhenPath("/my-page").RegisterHeadScript("MyPageScript");
    }
}

JavaScript Module Support

The ScriptModuleResourceFilter makes it possible to register JS modules in a way that they can be imported by name, so no bundling or importing by URL is necessary. Once you've added it to your service collection (services.AddAsyncResultFilter<ScriptModuleResourceFilter>();) you can register modules with the ResourceManifest.DefineScriptModule(resourceName) extension method and require them using the IResourceManager.RegisterScriptModule(resourceName) extension method.

You don't even have to register dependencies, because thanks to the importmap script generated by the ScriptModuleResourceFilter, you can import any resource using the import * from 'resourceName' syntax. You can see an example in Lombiq.VueJs where Vue 3 support is added ahead of Orchard Core by importing Vue 3 as a JS module.

Extensions

  • ApplicationBuilderExtensions: Shortcut extensions for application setup, such as UseResourceFilters() (see above).
  • ResourceFilterProviderExtensions: Extension methods for the IResourceFilterProvider interface.
  • ResourceManifestExtensions: Extensions for building the resource manifest, such as SetDependenciesRecursively() which helps registering multi-level dependencies.
  • ResourceManagerExtensions: Extensions for resource usage, such as RegisterStyle() which registers a stylesheet resource by name without having to use the error-prone "stylesheet" literal.