[Trimming] Fix trimming warnings related to image source service provider#20058
Conversation
src/Core/src/Hosting/ImageSources/ImageSourceToImageSourceServiceTypeMapping.cs
Outdated
Show resolved
Hide resolved
src/Core/src/Hosting/ImageSources/ImageSourceToImageSourceServiceTypeMapping.cs
Outdated
Show resolved
Hide resolved
src/Core/src/Hosting/ImageSources/ImageSourceToImageSourceServiceTypeMapping.cs
Outdated
Show resolved
Hide resolved
63e7432 to
7f4d26c
Compare
src/Core/src/Hosting/ImageSources/ImageSourceToImageSourceServiceTypeMapping.cs
Outdated
Show resolved
Hide resolved
src/Core/src/Hosting/ImageSources/ImageSourceToImageSourceServiceTypeMapping.cs
Outdated
Show resolved
Hide resolved
src/Core/src/Hosting/ImageSources/ImageSourceToImageSourceServiceTypeMapping.cs
Outdated
Show resolved
Hide resolved
src/Core/src/Hosting/ImageSources/ImageSourceToImageSourceServiceTypeMapping.cs
Outdated
Show resolved
Hide resolved
src/Core/src/Hosting/ImageSources/ImageSourceServiceProvider.cs
Outdated
Show resolved
Hide resolved
src/Core/src/Hosting/ImageSources/IImageSourceServiceProvider.cs
Outdated
Show resolved
Hide resolved
src/Core/tests/UnitTests/ImageSource/ImageSourceToImageSourceServiceTypeMappingTests.cs
Show resolved
Hide resolved
src/Core/tests/UnitTests/ImageSource/ImageSourceToImageSourceServiceTypeMappingTests.cs
Outdated
Show resolved
Hide resolved
8fce729 to
e62fedd
Compare
e62fedd to
3cf0b7f
Compare
src/Core/src/Hosting/ImageSources/ImageSourceToImageSourceServiceTypeMapping.cs
Outdated
Show resolved
Hide resolved
…iceTypeMapping.cs Co-authored-by: Mitchell Hwang <16830051+mdh1418@users.noreply.github.com>
| return (IImageSourceService?)GetService(imageSourceService); | ||
| } | ||
|
|
||
| public Type GetImageSourceServiceType(Type imageSource) => |
There was a problem hiding this comment.
Should this method now be calling _imageSourceMapping.FindImageSourceServiceType?
There was a problem hiding this comment.
I'm still trying to figure out if it's better to keep the old behavior of this method but make it obsolete (but GetImageSourceServiceType(imageSource) might not necessarily match GetImageSourceService(imageSource)?.GetType()) or to change the way this method behaves and break someone's expectations. I'm going back and forth on this.
|
This looks very nice and the added tests is also good. I did have a question about the method that used to be used We chatted about the fact that this potentially breaks people who bypass the Overall, this is a good change and helps clean up some of the old code that we wrote. |
|
Honestly, I wasn't sure what to do with the |
…image-source-service-provider
…image-source-service-provider
Description of Change
This PR removes trimming-unsafe patterns from
ImageSourceServiceProvider(MakeGenericType, iterating over implemented interfaces).Notes:
FindImageSourceToImageSourceServiceTypeMappingmethod uses linear search to find the mapping. Linear search is fine in this case for two reasons: there are usually few image source types and we're caching the results.IImageSourceServiceCollectioninterface but I came up with a workaround which doesn't need any changes to the public API and it will work with any customer implementation of the interface out of the box.IImageSourceServiceProvider.GetImageSourceTypeandIImageSourceServiceProvider.GetImageSourceServiceTypemethods now aren't used anywhere in the app. The main method,GetImageSourceService, doesn't use them and it uses the new mapping class instead. The implementation of these two methods is still trimming-unsafe and we might want to annotate them with[RequiresUnreferencedCode]and[RequiredsDynamicCode]once we enable trimming for the whole assembly. I think it is OK as is for the time being, customers would get trimming/AOT warnings when they call these methods themselves.Issues Fixed
Contriubtes to #19397
Alternative to #19641