File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed
src/Mvc/Mvc.Core/src/ModelBinding/Binders Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
1111 /// </summary>
1212 public class CancellationTokenModelBinderProvider : IModelBinderProvider
1313 {
14+ // CancellationTokenModelBinder does not have any state. Re-use the same instance for binding.
15+
16+ private readonly CancellationTokenModelBinder _modelBinder = new CancellationTokenModelBinder ( ) ;
17+
1418 /// <inheritdoc />
1519 public IModelBinder GetBinder ( ModelBinderProviderContext context )
1620 {
@@ -21,7 +25,7 @@ public IModelBinder GetBinder(ModelBinderProviderContext context)
2125
2226 if ( context . Metadata . ModelType == typeof ( CancellationToken ) )
2327 {
24- return new CancellationTokenModelBinder ( ) ;
28+ return _modelBinder ;
2529 }
2630
2731 return null ;
Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
1010 /// </summary>
1111 public class ServicesModelBinderProvider : IModelBinderProvider
1212 {
13+ // ServicesModelBinder does not have any state. Re-use the same instance for binding.
14+
15+ private readonly ServicesModelBinder _modelBinder = new ServicesModelBinder ( ) ;
16+
1317 /// <inheritdoc />
1418 public IModelBinder GetBinder ( ModelBinderProviderContext context )
1519 {
@@ -21,7 +25,7 @@ public IModelBinder GetBinder(ModelBinderProviderContext context)
2125 if ( context . BindingInfo . BindingSource != null &&
2226 context . BindingInfo . BindingSource . CanAcceptDataFrom ( BindingSource . Services ) )
2327 {
24- return new ServicesModelBinder ( ) ;
28+ return _modelBinder ;
2529 }
2630
2731 return null ;
You can’t perform that action at this time.
0 commit comments