Fork me on GitHub

Sharp App Plugins

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

Plugins allow "no touch" sharing of ServiceStack Plugins, Services, Script Methods Sharp Code Pages, Validators, etc. contained within .dll's or .exe's dropped in a Sharp 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 3.1 projects in the /plugins/src folder.

ScriptInfo Plugin

The /ScriptInfo plugin contains the ScriptServices which lets us evaluate templates via Ajax and the ScriptInfoMethods which provides the methodLinkToSrc and methodsAvailable script methods used below to provide the UI to quickly browse the different methods 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 app.settings:

debug true
name Plugins Sharp App
features CustomPlugin, OpenApiFeature, PostmanFeature, CorsFeature, ValidationFeature
CustomPlugin { ShowProcessLinks: true }
ValidationFeature { ScanAppHostAssemblies: true }
CefConfig { width:1150, height:1050 }

All plugins listed in features will be added to your Sharp 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";
                .AddPluginLink("/drives", "All Disks")
                .AddPluginLink($"/drives?DriveFormatIn={diskFormat}", $"{diskFormat} Disks");

        if (ShowProcessLinks)
                .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 App is the metadata Services required for Open API, Postman as well as support for CORS. You can check the Metadata Debug Inspector 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