Created
July 2, 2025 19:44
-
-
Save emonarafat/f12fba1f1c88950dbb8930dde26b647b to your computer and use it in GitHub Desktop.
π Simple .NET plugin architecture pattern using IPlugin and extension methods for modular service registration.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // PluginHostExtensions.cs | |
| public static class PluginHostExtensions | |
| { | |
| public static IServiceCollection AddPlugin<TPlugin>(this IServiceCollection services) | |
| where TPlugin : class, IPlugin, new() | |
| { | |
| var plugin = new TPlugin(); | |
| plugin.ConfigureServices(services); | |
| return services; | |
| } | |
| } | |
| public interface IPlugin | |
| { | |
| void ConfigureServices(IServiceCollection services); | |
| } | |
| // Example Plugin | |
| public class PaymentsFeature : IPlugin | |
| { | |
| public void ConfigureServices(IServiceCollection services) | |
| { | |
| services.AddScoped<IPaymentProcessor, StripePaymentProcessor>(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment