|
8 | 8 | using Microsoft.Extensions.Configuration; |
9 | 9 | using Microsoft.Extensions.DependencyInjection; |
10 | 10 | using Microsoft.Extensions.Hosting; |
11 | | -using Microsoft.IO; |
12 | 11 | using SixLabors.ImageSharp.Web.Caching; |
13 | 12 | using SixLabors.ImageSharp.Web.Commands; |
14 | 13 | using SixLabors.ImageSharp.Web.DependencyInjection; |
@@ -38,67 +37,97 @@ public class Startup |
38 | 37 | /// </summary> |
39 | 38 | /// <param name="services">The collection of service desscriptors.</param> |
40 | 39 | public void ConfigureServices(IServiceCollection services) |
41 | | - => services.AddImageSharp(); // Add the default services and options |
| 40 | + { |
| 41 | + services.AddImageSharp() |
| 42 | + .SetRequestParser<QueryCollectionRequestParser>() |
| 43 | + .Configure<PhysicalFileSystemCacheOptions>(options => |
| 44 | + { |
| 45 | + options.CacheRootPath = null; |
| 46 | + options.CacheFolder = "is-cache"; |
| 47 | + options.CacheFolderDepth = 8; |
| 48 | + }) |
| 49 | + .SetCache<PhysicalFileSystemCache>() |
| 50 | + .SetCacheKey<UriRelativeLowerInvariantCacheKey>() |
| 51 | + .SetCacheHash<SHA256CacheHash>() |
| 52 | + .Configure<PhysicalFileSystemProviderOptions>(options => |
| 53 | + { |
| 54 | + options.ProviderRootPath = null; |
| 55 | + }) |
| 56 | + .AddProvider<PhysicalFileSystemProvider>() |
| 57 | + .AddProcessor<ResizeWebProcessor>() |
| 58 | + .AddProcessor<FormatWebProcessor>() |
| 59 | + .AddProcessor<BackgroundColorWebProcessor>() |
| 60 | + .AddProcessor<QualityWebProcessor>(); |
| 61 | + |
| 62 | + // Add the default service and options. |
| 63 | + // |
| 64 | + // services.AddImageSharp(); |
| 65 | + |
| 66 | + // Or add the default service and custom options. |
| 67 | + // |
| 68 | + // this.ConfigureDefaultServicesAndCustomOptions(services); |
| 69 | + |
| 70 | + // Or we can fine-grain control adding the default options and configure all other services. |
| 71 | + // |
| 72 | + // this.ConfigureCustomServicesAndDefaultOptions(services); |
| 73 | + |
| 74 | + // Or we can fine-grain control adding custom options and configure all other services |
| 75 | + // There are also factory methods for each builder that will allow building from configuration files. |
| 76 | + // |
| 77 | + // this.ConfigureCustomServicesAndCustomOptions(services); |
| 78 | + } |
42 | 79 |
|
43 | | - // Or add the default services and custom options |
44 | 80 | private void ConfigureDefaultServicesAndCustomOptions(IServiceCollection services) |
45 | | - => services.AddImageSharp(options => |
| 81 | + { |
| 82 | + services.AddImageSharp(options => |
46 | 83 | { |
47 | 84 | options.Configuration = Configuration.Default; |
48 | | - options.MemoryStreamManager = new RecyclableMemoryStreamManager(); |
49 | | - options.UseInvariantParsingCulture = true; |
50 | 85 | options.BrowserMaxAge = TimeSpan.FromDays(7); |
51 | 86 | options.CacheMaxAge = TimeSpan.FromDays(365); |
52 | | - options.CacheHashLength = 12; |
| 87 | + options.CacheHashLength = 8; |
53 | 88 | options.OnParseCommandsAsync = _ => Task.CompletedTask; |
54 | 89 | options.OnBeforeSaveAsync = _ => Task.CompletedTask; |
55 | 90 | options.OnProcessedAsync = _ => Task.CompletedTask; |
56 | 91 | options.OnPrepareResponseAsync = _ => Task.CompletedTask; |
57 | 92 | }); |
| 93 | + } |
58 | 94 |
|
59 | | - // Or we can fine-grain control adding the default options and configure all other services |
60 | 95 | private void ConfigureCustomServicesAndDefaultOptions(IServiceCollection services) |
61 | | - => services.AddImageSharp() |
62 | | - .RemoveProcessor<FormatWebProcessor>() |
63 | | - .RemoveProcessor<BackgroundColorWebProcessor>(); |
| 96 | + { |
| 97 | + services.AddImageSharp() |
| 98 | + .RemoveProcessor<FormatWebProcessor>() |
| 99 | + .RemoveProcessor<BackgroundColorWebProcessor>(); |
| 100 | + } |
64 | 101 |
|
65 | | - // Or we can fine-grain control adding custom options and configure all other services |
66 | | - // There are also factory methods for each builder that will allow building from configuration files |
67 | 102 | private void ConfigureCustomServicesAndCustomOptions(IServiceCollection services) |
68 | | - => services.AddImageSharp(options => |
| 103 | + { |
| 104 | + services.AddImageSharp(options => |
69 | 105 | { |
70 | 106 | options.Configuration = Configuration.Default; |
71 | | - options.MemoryStreamManager = new RecyclableMemoryStreamManager(); |
72 | | - options.UseInvariantParsingCulture = true; |
73 | 107 | options.BrowserMaxAge = TimeSpan.FromDays(7); |
74 | 108 | options.CacheMaxAge = TimeSpan.FromDays(365); |
75 | | - options.CacheHashLength = 12; |
| 109 | + options.CacheHashLength = 8; |
76 | 110 | options.OnParseCommandsAsync = _ => Task.CompletedTask; |
77 | 111 | options.OnBeforeSaveAsync = _ => Task.CompletedTask; |
78 | 112 | options.OnProcessedAsync = _ => Task.CompletedTask; |
79 | 113 | options.OnPrepareResponseAsync = _ => Task.CompletedTask; |
80 | 114 | }) |
81 | | - .SetRequestParser<QueryCollectionRequestParser>() |
82 | | - .SetCache<PhysicalFileSystemCache>() |
83 | | - .Configure<PhysicalFileSystemCacheOptions>(options => |
84 | | - { |
85 | | - options.CacheFolder = "is-cache"; |
86 | | - options.CacheFolderDepth = 8; |
87 | | - }) |
88 | | - .SetCacheKey<UriRelativeLowerInvariantCacheKey>() |
89 | | - .SetCacheHash<SHA256CacheHash>() |
90 | | - .ClearProviders() |
91 | | - .AddProvider<PhysicalFileSystemProvider>() |
92 | | - .Configure<PhysicalFileSystemProviderOptions>(options => |
93 | | - { |
94 | | - options.ProviderRootPath = null; |
95 | | - options.ProcessingBehavior = ProcessingBehavior.CommandOnly; |
96 | | - }) |
97 | | - .ClearProcessors() |
98 | | - .AddProcessor<ResizeWebProcessor>() |
99 | | - .AddProcessor<FormatWebProcessor>() |
100 | | - .AddProcessor<BackgroundColorWebProcessor>() |
101 | | - .AddProcessor<QualityWebProcessor>(); |
| 115 | + .SetRequestParser<QueryCollectionRequestParser>() |
| 116 | + .Configure<PhysicalFileSystemCacheOptions>(options => |
| 117 | + { |
| 118 | + options.CacheFolder = "different-cache"; |
| 119 | + }) |
| 120 | + .SetCache<PhysicalFileSystemCache>() |
| 121 | + .SetCacheKey<UriRelativeLowerInvariantCacheKey>() |
| 122 | + .SetCacheHash<SHA256CacheHash>() |
| 123 | + .ClearProviders() |
| 124 | + .AddProvider<PhysicalFileSystemProvider>() |
| 125 | + .ClearProcessors() |
| 126 | + .AddProcessor<ResizeWebProcessor>() |
| 127 | + .AddProcessor<FormatWebProcessor>() |
| 128 | + .AddProcessor<BackgroundColorWebProcessor>() |
| 129 | + .AddProcessor<QualityWebProcessor>(); |
| 130 | + } |
102 | 131 |
|
103 | 132 | /// <summary> |
104 | 133 | /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. |
|
0 commit comments