// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.DependencyInjection;
namespace Microsoft.AspNet.Mvc
{
///
/// An which understands
/// and activates a given model using .
///
public class ServicesModelBinder : MetadataAwareBinder
{
///
protected override Task BindAsync(
[NotNull] ModelBindingContext bindingContext,
[NotNull] IServiceActivatorBinderMetadata metadata)
{
var requestServices = bindingContext.OperationBindingContext.HttpContext.RequestServices;
bindingContext.Model = requestServices.GetRequiredService(bindingContext.ModelType);
return Task.FromResult(true);
}
}
}