C
C#8mo ago
Bluestopher

❔ C# Design Pattern to Map to Implementation

Hey all, I’m working on a service that executes requests with a specific plug-in based on the plugin key the caller passes. Currently, I create a service class that contains a plug-in manager. The plugin manager registers all the plugins and manages executing the request by the specified plugin. Here is a simple example of how my service is structured: https://dotnetfiddle.net/5fwu23. I’m not sure if there is a better way to do this or specific design pattern to map to the correct implementation by a key. If you have any feedback on how I could design this better or a design pattern that fits this usecase let me know. If this is confusing let me know and I can give a better example.
5 Replies
JakenVeina
JakenVeina8mo ago
that seems pretty reasonable to me only thing I'd question is whether you could do all that with an IoC container
Bluestopher
Bluestopher8mo ago
@V.EINA Jaken IOC container for dependency injection for the plugins? Do you have an example of how that looks?
JakenVeina
JakenVeina8mo ago
put a name property on IPlugin register all IPligins with the IoC container have PluginService request IEnumerable<IPlugin> and create the index of them by name
Bluestopher
Bluestopher8mo ago
I see, thanks for the advice @V.EINA Jaken
Accord
Accord8mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.