Skip to content

Static Plugin Initializer #9

@TheBrambleShark

Description

@TheBrambleShark

Currently, plugin initialization takes three steps:

  1. Instantiate plugin (with new() constraint).
  2. Initialize plugin
  3. Execute plugin

This creates a bit of weird situation, where plugins must be instantiated before the service provider is built. This creates a bit of a catch 22 - the plugin may require assets from IServiceProvider, but these are not able to be injected, requiring us to inject a raw service provider into the starup function.

Instead, I would like to propose that a static plugin initializer be added to the IPlugin interface and the service provider parameter in InitializeAsync be removed.

/// <summary>
/// Configures services provided by the plugin in the application's service collection.
/// </summary>
/// <param name="serviceCollection">The service collection.</param>
/// <returns>The service collection, for chaining.</returns>
static abstract IServiceCollection ConfigureServices(IServiceCollection serviceCollection);

/// <summary>
/// Performs any post-registration initialization required by the plugin.
/// </summary>
/// </summary>
/// <param name="serviceProvider">The service provider.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A result that may or may not have succeeded.</returns>
ValueTask<Result> InitializeAsync(CancellationToken ct = default);

The new plugin initialization step would look like this:

  1. Initialize the plugin by calling the static ConfigureServices() method.
  2. Register the plugin with the service provider.
  3. Instantiate the plugin with the service provider, allowing for DI to provide resources and services.
  4. Call InitializeAsync() to start up the plugin.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions