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

Article typo or issue? #10

Closed
damienaicheh opened this issue Aug 20, 2021 · 2 comments
Closed

Article typo or issue? #10

damienaicheh opened this issue Aug 20, 2021 · 2 comments

Comments

@damienaicheh
Copy link

Hi Daniel,

I'm back for another question, in the article https://daniel-krzyczkowski.github.io/Cars-Island-ASP-NET-Core-API-Integration-With-Azure-Cosmos-DB/ you use TryAddSingleton to inject the dataservices.

In the next article : https://daniel-krzyczkowski.github.io/Cars-Island-ASP-NET-Core-API-Integration-With-Azure-Storage-Accont/ you are in the same case and you mention the AddSingleton
I have used services.AddSingleton with implementationFactory instead of just using services.AddSingleton.

Why not using the TryAddSingleton in both? is it a typo or a specific needs for storage service?

Thanks!

@damienaicheh damienaicheh changed the title Typo or issue? Article typo or issue? Aug 20, 2021
@Daniel-Krzyczkowski
Copy link
Owner

Thank you for catching this one. In general I try to use TryAddSingleton in the source code - inconsistency is by mistake.
TryAddSingleton appends the registration to the collection only when there is no registration for the given service type yet in the DI container.

@damienaicheh
Copy link
Author

Ok, thanks for your answer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants