question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Register / Resolve T or IEnumerable<T>

See original GitHub issue

Description

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 get DelegateB
  • When we Resolve<IEnumerable<ISomeDelegate>>() we should get back a collection with both DelegateA and DelegateB.

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:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dadhicommented, Jun 30, 2020

@dahlbyk

DryIoc supports resolving a few different collection types (everything implemented by object[]

It is correct. Plus its own LazyEnumerable.

Is there a downside to checking if a wrapper is registered for the specified type?

No downside I am aware of. That way you will check for whatever wrapper suported by DryIoc.

0reactions
dansiegelcommented, Aug 10, 2020

fixed by #126

Read more comments on GitHub >

github_iconTop Results From Across the Web

Autofac register IEnumerable and individuals to resolve ...
Registration sources are a way to do exactly what you want - provide one or more components to the container when a service...
Read more >
How to work with lists in .NET dependency injection
Register multiple instances of an interface and resolve as an IEnumerable. We'll be doing the examples as a FizzBuzz implementation and creating ...
Read more >
Dependency injection - .NET
The TryAddEnumerable(ServiceDescriptor) methods register the service only if there isn't already an implementation of the same type. Multiple ...
Read more >
Resolving collections of Objects of a Particular Type
When you want to obtain a list of all the registered objects of a specific type, IPrinter in this case, you can use...
Read more >
Implicit Relationship Types — Autofac 7.0.0 documentation
Autofac supports automatically resolving particular types implicitly to support special relationships between components and services. To take advantage of ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found