Fork me on GitHub

Web App Plugins

This demo shows an example of utilizing external Filters and Services that are automatically loaded from the Wep App's /plugins folder.

Plugins allow "no touch" sharing of ServiceStack Plugins, Services, Template Filters Template Code Pages, Validators, etc. contained within .dll's or .exe's dropped in a Web App's /plugins folder which are auto-registered on startup. This source code for plugins used in this App were built from the .NET Core 2.0 projects in the /example-plugins folder.

FilterInfo Plugin

The /FilterInfo plugin contains the EvaluateTemplateService which lets us evaluate templates via Ajax and the FilterInfoFilters which provides the filterLinkToSrc and filtersAvailable filters used below to provide the UI to quickly browse the different filters available in ServiceStack:


ServerInfo Plugin

The /ServerInfo plugin contains the ServerInfoFilters which gives our Templates access to this Server's Drive and Process Info used below:


ServerInfo Services

The ServerInfo Plugin's ServerInfoServices makes this Server's Drive and Process info available from the API endpoints below:

/drives API
All Drives
Disks formatted with NTFS or ext2
Disks larger than 1 GB
Disks smaller than 1 GB
/process API
Current Process
All Processes
Process by Id
'dotnet' Processes
Processes larger than 100 MB
More than 10 Active Threads

Contact Services

The ContactServices shows an example of a Service relying on ServiceStack's Validation Feature:

ServiceStack Features

The use of the ValidationFeature above shows an example of loading a ServiceStack Plugin by specifying it as a feature in its web.settings:

debug true
name Web App Plugins
port 5000
contentRoot ~/../plugins
webRoot ~/../plugins
features CustomPlugin, OpenApiFeature, PostmanFeature, CorsFeature, ValidationFeature
CustomPlugin { ShowProcessLinks: true }
ValidationFeature { ScanAppHostAssemblies: true }

All plugins listed in features will be added to your Web App's AppHost in the order they're specified. They can further customized by adding a separate config entry with the Plugin Name and a JavaScript Object literal to populate the Plugin at registration, e.g the config above is equivalent to:

Plugins.Add(new CustomPlugin { ShowProcessLinks = true });
Plugins.Add(new OpenApiFeature());
Plugins.Add(new PostmanFeature());
Plugins.Add(new CorsFeature());
Plugins.Add(new ValidationFeature { ScanAppHostAssemblies = true });

Custom Plugin

In this case it tells our CustomPlugin to also show Process Links in our /metadata Page:

public class CustomPlugin : IPlugin
{
    public bool ShowDrivesLinks { get; set; } = true;
    
    public bool ShowProcessLinks { get; set; }

    public void Register(IAppHost appHost)
    {
        if (ShowDrivesLinks)
        {
            var diskFormat = Env.IsWindows ? "NTFS" : "ext2";
            appHost.GetPlugin<MetadataFeature>()
                .AddPluginLink("/drives", "All Disks")
                .AddPluginLink($"/drives?DriveFormatIn={diskFormat}", $"{diskFormat} Disks");
        }

        if (ShowProcessLinks)
        {
            appHost.GetPlugin<MetadataFeature>()
                .AddPluginLink("/processes", "All Processes")
                .AddPluginLink("/process/current", "Current Process");
        }
    }
}

Where as it was first registered in the list will appear before any links registered by other plugins:

Metadata screenshot

Built-in Plugins

It also tells the ValidationFeature to scan all Service Assemblies for Validators and to automatically register them which is how ServiceStack was able to find the ContactValidator used to validate the StoreContact request.

Other optional plugins registered in this Web App is the metadata Services required for Open API, Postman as well as support for CORS. You can check the Metadata Debug Template for all Plugins loaded in your AppHost.

ServiceStack Metadata Services

All Services loaded by plugins continue to benefit from ServiceStack's rich metadata services, including being listed in the /metadata page, being able to explore and interact with Services using /swagger-ui/ as well as being able to generate Typed APIs for the most popular Mobile, Web and Desktop platforms.

made with by ServiceStack