-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Currently, plugin initialization takes three steps:
- Instantiate plugin (with
new()constraint). - Initialize plugin
- 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:
- Initialize the plugin by calling the static
ConfigureServices()method. - Register the plugin with the service provider.
- Instantiate the plugin with the service provider, allowing for DI to provide resources and services.
- Call
InitializeAsync()to start up the plugin.
VelvetToroyashi
Metadata
Metadata
Assignees
Labels
No labels