Register / Resolve T or IEnumerable<T>
See original GitHub issueDescription
As initially discussed in issue #115 we have an issue where IEnumerable<T> may need to be resolved. This is a particular issue with Shiny integration where multiple delegates may be registered and will need to be resolved.
Problem
Prism registers services with an expectation that we will internally only want to resolve the last registration for any particular service. However it is possible for developers, or 3rd party plugins such as Shiny to require registering multiple services as is the case for Delegates. In this scenario it would be normal to see:
c.Register<ISomeDelegate, DelegateA>();
c.Register<ISomeDelegate, DelegateB>();
Expectations
What we need is a proper ruleset for the Container so that:
- When we
Resolve<ISomeDelegate>()
we should getDelegateB
- When we
Resolve<IEnumerable<ISomeDelegate>>()
we should get back a collection with bothDelegateA
andDelegateB
.
NOTE: The registrations cannot directly reference the underlying container since this should transparently work with the Prism Container Abstractions and the integration where we convert from IServiceCollection to register each Service Descriptor with the Prism Container.
Observations
Currently we use the default IfAlreadyRegistered.Replace
, this satisfies the first requirement, but fails on the second as we only get a collection with DelegateB.
If we do not set the IfAlreadyRegistered behavior or set it explicitly to Append, we succeed on the second requirement but fail on the first.
cc: @dadhi… any thoughts?
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
@dahlbyk
It is correct. Plus its own
LazyEnumerable
.No downside I am aware of. That way you will check for whatever wrapper suported by DryIoc.
fixed by #126