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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update dotnet-8 KeyedSevice #38333
Update dotnet-8 KeyedSevice #38333
Conversation
there's no IKeyedServiceProvider registered
update SmallCacheConsumer
@ericstj Can you review this? |
Looks like this sample still doesn't work. Seems the Here's an update that works for me https://gist.github.com/ericstj/efd848d65ba6591546a2707897cad8fa. I'm not entirely sure if this communicates the concepts as cleanly. @steveharter @benjaminpetit what do you think? |
Oh yeah, thanks for the careful review @ericstj |
Thank you for the fix here. That original sample was something we copied from a tweet - not surprised it had multiple issues 馃槅. I would like either @steveharter or @benjaminpetit to weigh in on this before we merge. |
I think we should also show that you can use the app.MapGet("/big", ([FromKeyedServices("big")] ICache cache) => cache.Get("data")); But also showing the attribute usage in the constructor is important. So maybe we could so one of each, if that's not too weird? |
Make sense, how about adding the following two examples? app.MapGet("/big-cache", ([FromKeyedServices("big")] ICache cache) => cache.Get("data"));
app.MapGet("/small-cache", (HttpContext httpContext) => httpContext.RequestServices.GetRequiredKeyedService<ICache>("small").Get("data")); |
Yes that would be great! |
update keyedService example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - also tested this in a web project and all is working well
Summary
IServiceProvider
since there's noIKeyedServiceProvider
registeredSmallCacheConsumer
to get cache value instead of returning theIMemoryCache
Internal previews