1. Home
  2. Docs
  3. Documentation
  4. Plugins
  5. Server configuration

Server configuration

SB makes it easy to configure each plugin independently. The Startup class, which implements IConfigurable has a method ConfigureServices. This method has parameter of type IConfiguration.

The configuration parameter loads settings from a file appsettings.json. Each plugin can have their own settings file, which should be in the plugin folder. Best practice is to set the file to always copy to the output directory. Settings file is optional.

As an example, the CalculatorServer will take additional parameter, which contains starting state (for the method described in previous chapter), instead of 0.

The best way to configure plugins is to use the Options pattern, described here:
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options?view=aspnetcore-2.2

A quick description of the pattern: this pattern allows loading the setting file and mapping it to a certain class. Then the IOptions is injected in the plugin, and value can be read from that object.

The class for options is named CalculatorOptions, and has this definition:

namespace SB.Plugins.Demo.Server
{
    public class CalculatorOptions
    {
        public int StartingValue { get; set; }
    }
}

The settings file is named appsettings.json, it is set to always copy to the output directory, and has this content:

{
  "CalculatorOptions": {
    "StartingValue": 15
  }
}

And the last step is to use the value in the constructor of the plugin:

public CalculatorServer(
    IOptions<CalculatorOptions> options,
    ...)
{
    ...

    // read Starting value from the config file
    this.state = options.Value.StartingValue;

    ...
}

Of course, this is just one way to load the settings. For more info how to use the IConfiguration, read the asp.net core documentation.

There are a few settings that apply to the server itself. These are found in server’s root directory, in a file appsettings.json. Most notably, the LicenseKey setting needs to be changed for the server to work.

Next step: Server logging.

Was this article helpful to you? Yes No

How can we help?