vendredi 26 janvier 2018

Best way to pass data into plugin objects

I often have the problem that I have different plugins that all essentially perform the same task, but all in a different way. So each plugin needs different kinds of parameters, but how to pass them?

IMySpecificTask plugin = PluginResolver.Resolve(typeof(IMySpecificTask));

Each implementation of IMySpecificTask needs different objects of my domain which it needs to access. I could certainly use a service locator/singleton pattern to get the information which I need but isn't there a cleaner way?

Another way I could think of but which also seem fishy to me is something like this:

if (plugin is INeedsServiceA a)
    a.SetServiceA(myserviceA);
if (plugin is INeedsServiceB b)
    b.SetServiceB(myserviceB);
...

Aucun commentaire:

Enregistrer un commentaire