dotnet-object-storage/PoweredSoft.ObjectStorage.MongoDB.AspNetCore/ObjectIdModelBinderProvider.cs

20 lines
568 B
C#
Raw Normal View History

2019-02-15 12:08:37 -05:00
using System;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using MongoDB.Bson;
namespace PoweredSoft.ObjectStorage.MongoDB.AspNetCore
{
public class ObjectIdModelBinderProvider : IModelBinderProvider
{
public IModelBinder GetBinder(ModelBinderProviderContext context)
{
if (context == null)
throw new ArgumentNullException(nameof(context));
if (context.Metadata.ModelType == typeof(ObjectId))
return new ObjectIdModelBinder();
return null;
}
}
}