mercredi 7 décembre 2016

Locate different generic services in one non generic Locator

I have various Services that implement

public interface IReceiver<PayLoad>
{
    string Name {get;}
    Task SendObjectContainerAsync(ObjectContainer<PayLoad> m);
    Task<ObjectContainer<PayLoad>> GetSnapshot();
}

For Example

public class Printer : IReceiver<TextDocument>

or

public class TextDocumentService : IReceiver<Letter>

Now I want to collect all instances of each IReceiver in one Controller, I could

public class Broker<Payload>
{
     List<IReceiver<Payload>> receivers;         
}

and initialize an Instance for each type of IReceiver and then DI it into the IReceivers to enable them to register and get the Instances from other places.

Is this a good way to handle different Services? I think it gets kind of messy with many Brokers and I would rather have something like

static void register<Payload>(IReceiver<Payload> RegisterMe)

and

static List<IReceiver<Payload>> getReceivers<PayLoad>()

But im not able to implement this Locator because I dont know how to administrate different generic Lists in one non generic class

Any Suggestions?

Aucun commentaire:

Enregistrer un commentaire