-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
Replace IImageProvider.Get() with GetAsync() #48
Replace IImageProvider.Get() with GetAsync() #48
Conversation
This makes it possible for implementations of IImageProvider that rely on remote image sources to asynchronously create an IImageResolver. This is important as it allows them to determine whether the requested image exists or not in an asynchronous manner prior to returning the IImageResolver.
Interesting, I think this was changed in the last beta, and the async logic is actually in the |
The issue with having the async logic in the IImageResolver and not in the IImageProvider is that you have to determine whether or not the source image exists in the provider prior to creating the resolver. If the source image doesn't exist, then the IImageProvider.Get() method needs to return null. If instead you speculatively return an IImageResolver that later determines that the source image doesn't exist, there's no way to deal with it at that point. Attempting to return null from the IImageResolver.OpenReadAsync() method results in a NullReferenceException. I had a quick discussion about this with @JimBobSquarePants on gitter and he agreed that this change seemed like the simplest and most logical solution to the problem. |
I am not disagreeing. and If the boss said so then it's all good. |
Yeah, oversight on my part. No way to check if the file exists asynchronously in Azure for example. I'm gonna merge this in, and then build a separate project with an Azure blob resolver to make sure it's all sensible before shipping another beta. |
In case it's useful, here's a quick sample I threw together that uses an Azure Blob Storage account as the image source: https://gist.github.com/kroymann/8955c5ebb1d89a04c206f90d92a286c1 |
Very useful, thanks! I've started putting together an official version based on your code. There's a few performance fixes in there plus access control settings |
Prerequisites
Description
This makes it possible for implementations of IImageProvider that rely on remote image sources to asynchronously create an IImageResolver. This is important as it allows them to determine whether the requested image exists or not in an asynchronous manner prior to returning the IImageResolver.