Skip to content

feat: validate plugin dependencies during plugin loading - #41

Merged
DevD4v3 merged 6 commits into
masterfrom
feature/plugin-dependencies
Jul 29, 2026
Merged

feat: validate plugin dependencies during plugin loading#41
DevD4v3 merged 6 commits into
masterfrom
feature/plugin-dependencies

Conversation

@DevD4v3

@DevD4v3 DevD4v3 commented Jul 29, 2026

Copy link
Copy Markdown
Owner

Summary

This PR introduces support for plugin dependencies through the new DependsOnAttribute.

During plugin loading, CPlugin.Net validates that every declared dependency is also present in the configured plugin list. If a dependency cannot be resolved, plugin loading fails with a PluginDependencyException.

This helps detect configuration errors early and prevents plugins from running with missing requirements.

Usage

[assembly: Plugin(typeof(GunGameCommand))]
// GunGame consumes IWeapon services registered by WeaponsPlugin.
// Therefore, WeaponsPlugin must also be included in the plugin configuration.
[assembly: DependsOn("WeaponsPlugin")]

namespace GunGamePlugin;

internal class GunGameCommand(IEnumerable<IWeapon> weapons) : ICommand
{
    public string Name => "gungame";
    public string Description => "Lists the available weapons.";
    public string Version => "1.0.0";

    public int Execute()
    {
        Console.WriteLine();
        Console.WriteLine("Registered weapons:");

        foreach (IWeapon weapon in weapons.OrderBy(w => w.Slot))
        {
            Console.WriteLine($"  [{weapon.Slot}] {weapon.Name} (Id: {weapon.Id})");
        }

        Console.WriteLine();
        return 0;
    }
}

If the Weapons plugin is not listed in the plugin configuration (for example, in appsettings.json or a .env file), PluginLoader.Load(...) throws:

PluginDependencyException:
The plugin 'GunGamePlugin' depends on 'WeaponsPlugin', but 'WeaponsPlugin' was not found in the plugin configuration.

Changes

  • Added DependsOnAttribute.
  • Added PluginDependencyException.
  • Added dependency validation during plugin loading.
  • Added sample plugins demonstrating plugin dependencies.
  • Added XML documentation.

Motivation

Some plugins require services, commands, or other components provided by another plugin.

Previously, these relationships were implicit and configuration errors were only discovered later at runtime.

With this change, plugin dependencies become explicit and are validated during plugin loading, allowing configuration issues to be detected immediately with a clear error message.

DevD4v3 added 6 commits July 29, 2026 10:42
Introduce the DependsOnAttribute to declare plugin dependencies and validate them during plugin loading.

PluginLoader now throws PluginDependencyException when a declared dependency cannot be resolved from the configured plugin list.
Add sample plugins demonstrating how to declare plugin dependencies using DependsOnAttribute and how plugins can consume services registered by other plugins.
Remove the redundant normalization of configured plugin names.

CPluginConfigurationBase already guarantees that plugin files use the .dll extension, so only dependency names declared with DependsOnAttribute need to be normalized before comparison.
Add tests covering plugin dependency validation.

Verify that PluginLoader throws PluginDependencyException when a dependency is missing and successfully loads plugins when all declared dependencies are configured.
@DevD4v3
DevD4v3 force-pushed the feature/plugin-dependencies branch from db20e57 to 7c5ba39 Compare July 29, 2026 19:38
@DevD4v3
DevD4v3 merged commit 3ff5af5 into master Jul 29, 2026
1 check passed
@DevD4v3
DevD4v3 deleted the feature/plugin-dependencies branch July 29, 2026 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant