public sealed class PluginContext : Moka.Docs.Plugins.IPluginContext
Namespace: Moka.Docs.Plugins
Inheritance
Implements: Moka.Docs.Plugins.IPluginContext
Constructors
| Name | Description |
|---|---|
PluginContext(…) |
Creates a new plugin context. |
PluginContext(SiteConfig siteConfig, IReadOnlyDictionary options, IServiceProvider serviceProvider, ILogger logger)
PluginContext.PluginContext(SiteConfig siteConfig, IReadOnlyDictionary<string, object> options, IServiceProvider serviceProvider, ILogger logger)
Creates a new plugin context.
Parameters
| Name | Type | Description |
|---|---|---|
siteConfig | SiteConfig | The site configuration. |
options | IReadOnlyDictionary<string, object> | Plugin-specific options from configuration. |
serviceProvider | IServiceProvider | The host service provider for resolving services. |
logger | ILogger | Logger scoped to the plugin. |
Properties
| Name | Description |
|---|---|
Options |
Plugin-specific options from the plugins[].options section of mokadocs.yaml. |
SiteConfig |
The current site configuration. |
Options
IReadOnlyDictionary<string, object> PluginContext.Options { get; }
Plugin-specific options from the plugins[].options section of mokadocs.yaml.
SiteConfig
SiteConfig PluginContext.SiteConfig { get; }
The current site configuration.
Methods
| Name | Description |
|---|---|
GetService() |
Resolves a service from the host DI container. |
LogError(string message) |
Logs an error message from the plugin. |
LogInfo(string message) |
Logs an informational message from the plugin. |
LogWarning(string message) |
Logs a warning message from the plugin. |
GetService()
T? PluginContext.GetService<T>()
Resolves a service from the host DI container.
Returns: The resolved service, or null if not registered.
LogError(string message)
void PluginContext.LogError(string message)
Logs an error message from the plugin.
Parameters
| Name | Type | Description |
|---|---|---|
message | string | The error message. |
LogInfo(string message)
void PluginContext.LogInfo(string message)
Logs an informational message from the plugin.
Parameters
| Name | Type | Description |
|---|---|---|
message | string | The log message. |
LogWarning(string message)
void PluginContext.LogWarning(string message)
Logs a warning message from the plugin.
Parameters
| Name | Type | Description |
|---|---|---|
message | string | The warning message. |
Type Relationships
classDiagram
style PluginContext fill:#f9f,stroke:#333,stroke-width:2px
PluginContext ..|> IPluginContext : implements
View Source
/// <summary>
/// Default implementation of <see cref = "IPluginContext"/> that wraps the host
/// service provider and plugin-specific options from configuration.
/// </summary>
public sealed class PluginContext : IPluginContext
{
private readonly ILogger _logger;
private readonly IServiceProvider _serviceProvider;
/// <summary>
/// Creates a new plugin context.
/// </summary>
/// <param name = "siteConfig">The site configuration.</param>
/// <param name = "options">Plugin-specific options from configuration.</param>
/// <param name = "serviceProvider">The host service provider for resolving services.</param>
/// <param name = "logger">Logger scoped to the plugin.</param>
public PluginContext(SiteConfig siteConfig, IReadOnlyDictionary<string, object> options, IServiceProvider serviceProvider, ILogger logger)
{
SiteConfig = siteConfig;
Options = options;
_serviceProvider = serviceProvider;
_logger = logger;
}
/// <inheritdoc/>
public SiteConfig SiteConfig { get; }
/// <inheritdoc/>
public IReadOnlyDictionary<string, object> Options { get; }
/// <inheritdoc/>
public T? GetService<T>()
where T : class => _serviceProvider.GetService(typeof(T)) as T;
/// <inheritdoc/>
public void LogInfo(string message) => _logger.LogInformation("[Plugin] {Message}", message);
/// <inheritdoc/>
public void LogWarning(string message) => _logger.LogWarning("[Plugin] {Message}", message);
/// <inheritdoc/>
public void LogError(string message) => _logger.LogError("[Plugin] {Message}", message);
}