Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs for members in DependencyInjection.Abstractions lack exception information. #108024

Open
ericstj opened this issue Sep 19, 2024 · 2 comments
Labels
area-Extensions-DependencyInjection documentation Documentation bug or enhancement, does not impact product or test code
Milestone

Comments

@ericstj
Copy link
Member

ericstj commented Sep 19, 2024

Description

I heard feedback that folks felt the docs for AddSingleton lacked good information about when it would fail and why.

I took a look and I agree. It seems that whenever we have a method with a corresponding Try method, we should be sure to include the exception docs. That will help folks if they need to use the Try method always, or if they would prefer to just use the non-try method for simpler code and treat the exception case as an invalid configuration.

Reproduction Steps

Have a look at docs https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.servicecollectionserviceextensions.addsingleton?view=net-8.0

Expected behavior

Information about meaningful thrown exceptions exists.

Actual behavior

No information exists

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Sep 19, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Sep 19, 2024
@jkotas jkotas added area-Extensions-DependencyInjection documentation Documentation bug or enhancement, does not impact product or test code and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Sep 19, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection
See info in area-owners.md if you want to be subscribed.

@steveharter steveharter added this to the 10.0.0 milestone Sep 19, 2024
@steveharter steveharter removed the untriaged New issue has not been triaged by the area owner label Sep 19, 2024
@KalleOlaviNiemitalo
Copy link

The difference between AddSingleton and TryAddSingleton is not like the difference between Int32.Parse and Int32.TryParse.

TryAddSingleton is not a way to avoid exceptions that AddSingleton would throw. Rather, the difference is in what happens if an implementation has already been added for the service. In that case, TryAddSingleton returns false and does not add the new implementation. In contrast, AddSingleton adds the new implementation regardless, so the service will then have two implementations; GetService(typeof(TService)) will return the last one registered, but GetService(typeof(IEnumerable<TService>)) will return both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Extensions-DependencyInjection documentation Documentation bug or enhancement, does not impact product or test code
Projects
None yet
Development

No branches or pull requests

4 participants