Skip to content

Platform-Agnostic Plugin Configuration #3

Description

@wendellmva

🚀 Feature: Platform-Agnostic Plugin Configuration via IContainer + Optional Host Context

Summary

Refactor the plugin system to support cross-platform compatibility by introducing a unified Configure method that uses dependency injection (IContainer) and an optional host parameter for platform-specific needs.

Problem

The current plugin model uses platform-bound signatures such as:

Task Configure(WebApplication app)

This introduces a hard dependency on Microsoft.AspNetCore.App, which causes build failures on unsupported platforms (e.g., android-x64 in .NET MAUI). Since plugins are intended to be shared across platforms (Web + MAUI), we need a way to configure them without leaking host-specific types into the shared core.

Proposed Solution

Replace the platform-specific Configure() method with a platform-neutral version:

public virtual Task Configure(IContainer container, object? host)
  • IContainer provides access to all services registered by the host
  • host is an optional object that may be:
    • WebApplication (in Web)
    • MauiAppBuilder (in MAUI)
    • or null, depending on the platform
  • Plugin authors can perform explicit type checks or casts based on what they need

Example usage:

public override async Task Configure(IContainer container, object? host)
{
    if (host is WebApplication app)
    {
        await app.UseMigration<MyContext>();
    }

    var factory = container.GetInstance<IDbContextFactory<MyContext>>();
    var context = await factory.CreateDbContextAsync();
    await context.RunMigration();
}

In the host project, plugin execution becomes explicit:

foreach (var plugin in container.GetAllInstances<IPlugin>())
{
    await plugin.Configure(container, app); // `app` can be WebApplication, MauiAppBuilder, etc.
}

This keeps plugin logic centralized and platform-neutral while still allowing platform-specific behavior when needed.

Benefits

  • ✅ Avoids cross-platform build failures
  • ✅ Keeps LowlandTech.Core completely platform-agnostic
  • ✅ Single plugin class supports multiple environments
  • ✅ Host control stays explicit
  • ✅ No #if directives or runtime checks are required unless desired

Status

  • Define Configure(IContainer container, object? host) in Plugin base class
  • Update all plugin implementations
  • Update plugin loading/invocation in all hosts (Web/Maui)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions