Skip to content

Wallsmedia/DotNetCore.Mps.Runtime

Repository files navigation

DotNetCore MicroService Platform Runtime Configuration

DotNetCore.Mps.Runtime - configuration provider that injects into IConfiguration collected runtime information.

Nuget.org

Version: 8.0.x

  • supports netstandard2.0/2.1 ; net8.0

Setup in the project

      // Adds Runtime Configuration
       builder.Configuration.AddMpsRuntimeWithMicroServiceName(typeof(Program).Assembly);

or with exact microservice name.

      // Adds Runtime Configuration
       builder.Configuration.AddMpsRuntimeWithMicroServiceName(microserviceName: "MyMicroserviceName");

Get MpsRuntime class object

     MpsRuntime mpsRuntime = builder.Configuration.GetSection(nameof(MpsRuntime)).Get<MpsRuntime>();
     builder.Services.AddSingleton(mpsRuntime);

IConfiguration Values:

Configuration path/key Value
mps:env Value defined by Environment microservice_environment, default value is dev
mps:msname Microservice name. Value defined by Assembly "AssemblyProductAttribute" attribute or via "MpsRuntimeConfigurationOptions"
mps:docker "true" is runs in docker container
mps:host Value of environment "MachineName"
mps:bus Service bus name either the mps:env value or mps:host
mps:linux "true" when run on linux

Runtime Customization

Use configuration

public class MpsRuntimeConfigurationOptions
{
    /// <summary>
    /// A Microservice assembly; it's used for accessing the <see cref="AssemblyProductAttribute"/>
    /// which is used as MicroserviceName for a runtime configuration.
    /// </summary>
    public Assembly MpsAssembly { get; set; }

    /// <summary>
    /// Set the valid list of configurations.
    /// The default list is  "sbx", "dev", "uat", "qat", "stg", "pdn", "prd" 
    /// </summary>
    public string[] ValidMpsConfigs { get; set; } = MpsRuntimeConfigurationProvider.ValidMpsConfigs;

    /// <summary>
    /// A microservice name. The default name is 'mps-microservice-api'.
    /// </summary>
    public string MicroserviceName { get; set; } = MpsRuntimeConfigurationProvider.DefaultMicroserviceName;

    /// <summary>
    /// A prefix used as name of the section  variables. The default value is 'mps'.
    /// </summary>
    public string Section { get; set; } = MpsRuntimeConfigurationProvider.DefaultSection;

    /// <summary>
    /// An environment name. The default name is 'microservice_environment'.
    /// </summary>
    public string MpsEnvironmentName { get; set; } = MpsRuntimeConfigurationProvider.EnvMpsEnvironment;
}

Runtime information logging

     MpsRuntime mpsRuntime = builder.Configuration.GetSection(nameof(MpsRuntime)).Get<MpsRuntime>();
     builder.Services.AddSingleton(mpsRuntime);
     builder.Services.AddHostedService<MpsLifetimeEventsHostedService>();

Enterprise Configuration Integrations

DotNetCore.Mps.Runtime - can be used with DotNetCore Generic Configuration.

DotNetCore Generic Configuration creates a new configuration values by substituting IConfiguration Keys with Values from other IConfiguration Keys.

References:

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages