mercredi 21 décembre 2016

C# how to "register" class "plug-ins" into a service class?

I'm trying to implement something like the idea I'm trying to show with the following diagram (end of the question).

Everything is coded from the abstract class "Base" till the "DoSomething" classes.

My "Service" needs to provide to the consumer "actions" of the type "DoSomethings" that the service has "registered", at this point I am seeing my self as repeating (copy/paste) the following logic on the service class:

public async Task<Obj1<XXXX>> DoSomething1(....params....)
        {
            var action = new DoSomething1(contructParams);
            return await action.Go(....params....);
        }

I would like to know if there is anyway in C# to "register" all the "DoSomething" I want in a different way? Something more dynamic and less "copy/paste" and at the same time provide me the "intellisense" in my consumer class? Somekind of "injecting" a list of accepted "DoSomething" for that service.

enter image description here

Aucun commentaire:

Enregistrer un commentaire