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

Add InsertProvider extensions and tests #247

Merged
merged 2 commits into from
Apr 5, 2022
Merged

Conversation

JimBobSquarePants
Copy link
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

Adds the ability to insert an IImageProvider or factory into the provider collection. This reduces boilerplate code when adding multiple providers.

@codecov
Copy link

codecov bot commented Apr 4, 2022

Codecov Report

Merging #247 (198e8f4) into main (8892d76) will increase coverage by 0%.
The diff coverage is 100%.

@@         Coverage Diff         @@
##           main   #247   +/-   ##
===================================
  Coverage    84%    84%           
===================================
  Files        75     75           
  Lines      2036   2045    +9     
  Branches    294    296    +2     
===================================
+ Hits       1722   1733   +11     
+ Misses      230    228    -2     
  Partials     84     84           
Flag Coverage Δ
unittests 84% <100%> (+<1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...DependencyInjection/ImageSharpBuilderExtensions.cs 97% <100%> (+<1%) ⬆️
.../Synchronization/RefCountedConcurrentDictionary.cs 76% <0%> (+4%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8892d76...198e8f4. Read the comment docs.

Copy link
Contributor

@ronaldbarendse ronaldbarendse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but the lifetime check can probably be skipped (same for removing), because clearing the providers/processors uses Services.RemoveAll() that only looks at the service type anyway.

@JimBobSquarePants
Copy link
Member Author

@ronaldbarendse Agreed. Removed that additional check.

@JimBobSquarePants JimBobSquarePants merged commit b922f29 into main Apr 5, 2022
@JimBobSquarePants JimBobSquarePants deleted the js/insert-provider branch April 5, 2022 06:03
@ronaldbarendse
Copy link
Contributor

I had another look at this and there are some issues with the current implementation:

builder.ClearProviders();
builder.AddProvider<PhysicalFileSystemProvider>();
builder.AddProvider<MockImageProvider>();
builder.InsertProvider<MockImageProvider>(2); // Does not throw ArgumentOutOfRangeException, because it's inserted after the existing 2 providers, but TryAddEnumerable only adds the first implementation
builder.ClearProviders();
builder.AddProvider<PhysicalFileSystemProvider>();
builder.InsertProvider<MockImageProvider>(0);
builder.InsertProvider<MockImageProvider>(1); // Does not change the index to 1 (last), because there's already an implementation added before it

See the implementation of TryAddEnumerable.

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

Successfully merging this pull request may close these issues.

2 participants