Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
/// </summary>
public class CancellationTokenModelBinderProvider : IModelBinderProvider
{
// CancellationTokenModelBinder does not have any state. Re-use the same instance for binding.

private readonly CancellationTokenModelBinder _modelBinder = new CancellationTokenModelBinder();

/// <inheritdoc />
public IModelBinder GetBinder(ModelBinderProviderContext context)
{
Expand All @@ -21,7 +25,7 @@ public IModelBinder GetBinder(ModelBinderProviderContext context)

if (context.Metadata.ModelType == typeof(CancellationToken))
{
return new CancellationTokenModelBinder();
return _modelBinder;
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
/// </summary>
public class ServicesModelBinderProvider : IModelBinderProvider
{
// ServicesModelBinder does not have any state. Re-use the same instance for binding.

private readonly ServicesModelBinder _modelBinder = new ServicesModelBinder();

/// <inheritdoc />
public IModelBinder GetBinder(ModelBinderProviderContext context)
{
Expand All @@ -21,7 +25,7 @@ public IModelBinder GetBinder(ModelBinderProviderContext context)
if (context.BindingInfo.BindingSource != null &&
context.BindingInfo.BindingSource.CanAcceptDataFrom(BindingSource.Services))
{
return new ServicesModelBinder();
return _modelBinder;
}

return null;
Expand Down