Uso l'unità per gestire i miei servizi sul mio server delle app, ma per qualche motivo non riesco a far funzionare il metodo 'GetAllInstances'. La cosa strana è che "GetInstance" per lo stesso tipo sembra funzionare bene!Unity 'GetAllInstances' non restituisce nulla
Ecco la configurazione:
<alias alias="IService" type="Atom.Server.Infrastructure.Interface.Service.IService, Atom.Server.Infrastructure.Interface"/>
<alias alias="IAtomCommandService" type="Atom.CommandServer.AtomCommandService.Interface.IAtomCommandService, Atom.CommandServer.AtomCommandService.Interface"/>
<alias alias="AtomCommandService" type="Atom.CommandServer.AtomCommandService.AtomCommandService, Atom.CommandServer.AtomCommandService"/>
<register type="IService" mapTo="AtomCommandService">
<lifetime type="Singleton"/>
</register>
<register type="IAtomCommandService" mapTo="AtomCommandService">
<lifetime type="Singleton"/>
</register>
L'idea è che quando il server si avvia, ho bisogno di essere in grado di ottenere tutte le istanze configurate di IService per inizializzare loro.
IUnityContainer container = ConfigureUnityContainer();
UnityServiceLocator locator = new UnityServiceLocator(container);
var single = locator.GetInstance<IService>();
var all = locator.GetAllInstances<IService>().ToList();
Come ho detto, il singolo funziona, ma il risultato non restituisce nulla. Anche se rimuovo il mapping IAtomCommandService dalla configurazione e ho solo l'IService, non funziona ancora. Qualche idea su dove sto andando male con questo?
Grazie Mark - L'ho capito subito dopo aver postato la domanda! Sempre la strada! –