File tree 2 files changed +14
-4
lines changed
src/Microsoft.AspNetCore.Mvc.Versioning/Routing 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 1
1
namespace Microsoft . AspNetCore . Mvc . Routing
2
2
{
3
3
using Microsoft . AspNetCore . Http ;
4
- using Microsoft . AspNetCore . Mvc . Versioning ;
5
4
using Microsoft . AspNetCore . Routing ;
6
5
using System ;
7
6
Original file line number Diff line number Diff line change @@ -28,12 +28,23 @@ public virtual IUrlHelper GetUrlHelper( ActionContext context )
28
28
throw new ArgumentNullException ( nameof ( context ) ) ;
29
29
}
30
30
31
- var urlHelper = new ApiVersionUrlHelper ( context , Factory . GetUrlHelper ( context ) ) ;
31
+ var items = context . HttpContext . Items ;
32
32
33
33
// REF: https://github.com/dotnet/aspnetcore/blob/master/src/Mvc/Mvc.Core/src/Routing/UrlHelperFactory.cs#L44
34
- context . HttpContext . Items [ typeof ( IUrlHelper ) ] = urlHelper ;
34
+ if ( ! items . TryGetValue ( typeof ( IUrlHelper ) , out var value ) )
35
+ {
36
+ var urlHelper = new ApiVersionUrlHelper ( context , Factory . GetUrlHelper ( context ) ) ;
37
+ items [ typeof ( IUrlHelper ) ] = urlHelper ;
38
+ return urlHelper ;
39
+ }
40
+
41
+ if ( value is not ApiVersionUrlHelper outer )
42
+ {
43
+ var inner = value as IUrlHelper ?? Factory . GetUrlHelper ( context ) ;
44
+ items [ typeof ( IUrlHelper ) ] = outer = new ApiVersionUrlHelper ( context , inner ) ;
45
+ }
35
46
36
- return urlHelper ;
47
+ return outer ;
37
48
}
38
49
}
39
50
}
You can’t perform that action at this time.
0 commit comments