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

Remove no-op ImageSharpConfiguration and setup action #245

Conversation

ronaldbarendse
Copy link
Contributor

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

I noticed a no-op ImageSharpConfiguration instance and an empty lambda for the setup action was registered: both don't add anything besides additional logic that's run when getting an IOptions<ImageSharpMiddlewareOptions>.

@codecov
Copy link

codecov bot commented Apr 2, 2022

Codecov Report

Merging #245 (2d5e0d4) into main (669b403) will increase coverage by 0%.
The diff coverage is n/a.

@@         Coverage Diff         @@
##           main   #245   +/-   ##
===================================
  Coverage    85%    85%           
===================================
  Files        75     74    -1     
  Lines      2030   2028    -2     
  Branches    297    297           
===================================
  Hits       1734   1734           
+ Misses      212    210    -2     
  Partials     84     84           
Flag Coverage Δ
unittests 85% <ø> (+<1%) ⬆️

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

Impacted Files Coverage Δ
...DependencyInjection/ServiceCollectionExtensions.cs 100% <ø> (ø)
.../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 669b403...2d5e0d4. Read the comment docs.

return builder;
}

private static IImageSharpBuilder AddDefaultServices(this IImageSharpBuilder builder)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although default implementations are also set for IRequestParser, IImageCache, ICacheKey and ICacheHash, those are actually required for ImageSharpMiddleware to activate/resolve from the service container and can easily be replaced with the respective set-methods.

Maybe this extension method should be made public and the AddImageSharp() shouldn't call it by default, so you can opt-in to adding these default providers/processors? And following this pattern, maybe even split it into AddDefaultProviders() and AddDefaultProcessors()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would also solve the issue I described in PR #185: the order of registering IImageProviders is important, but can't be (easily) changed. Having a separate method to add the default provider after your own will remove the need to remove and re-add them...

Copy link
Member

Choose a reason for hiding this comment

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

I don’t want to change registration methods at this time.

Copy link
Member

Choose a reason for hiding this comment

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

The whole point of the default implementation is that out of the box it works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure about this either and agree that it's better to have everything working OOTB 😄 I see you've also made inserting providers easier in #247, so this is now less of an issue...

Copy link
Member

@JimBobSquarePants JimBobSquarePants left a comment

Choose a reason for hiding this comment

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

Please revert all other changes and remove the no-op ImageSharpConfiguration class only.

The samples serve two purposes and should remain untouched.

  • Education
  • API sense checking.

@@ -37,71 +37,32 @@ public class Startup
/// </summary>
/// <param name="services">The collection of service desscriptors.</param>
public void ConfigureServices(IServiceCollection services)
{
Copy link
Member

Choose a reason for hiding this comment

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

You still need to revert all the changes bar removing ImageSharpConfiguration

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The default configuration is already documented in the ConfigureCustomServicesAndCustomOptions() method and having the sample site use the minimal, default AddImageSharp() will ensure it's actually running with the default configuration that's added by the ImageSharpBuilder 👍🏻

Copy link
Member

Choose a reason for hiding this comment

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

It makes it much more difficult for me to play around with though. We have unit tests for DI.

{
builder.Services.Configure(setupAction);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One thing this call did was internally call AddOptions(), so the generic options interfaces are registered and can be resolved from the service container.

Looking at other extension methods in ASP.NET Core, they do explicitly call AddOptions() as well, so let's make sure ImageSharp.Web does the same (even if it's probably already added anyway, we can't be sure though).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I'm sorry but I simply do not follow. Why are you changing any of this? We're only supposed to be removing the no-op ImageSharpConfiguration

Copy link
Member

@JimBobSquarePants JimBobSquarePants left a comment

Choose a reason for hiding this comment

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

Thanks! 👍

@JimBobSquarePants JimBobSquarePants added this to the v2.0.0 milestone Apr 22, 2022
@JimBobSquarePants JimBobSquarePants merged commit ba216da into SixLabors:main Apr 22, 2022
@ronaldbarendse ronaldbarendse deleted the feature/cleanup-di-configuration branch April 22, 2022 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants