// 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.Threading.Tasks; using Microsoft.Framework.DependencyInjection; namespace Microsoft.AspNet.Mvc.ModelBinding { /// /// An which binds models from the request services when a model /// has the binding source / /// public class ServicesModelBinder : BindingSourceModelBinder { /// /// Creates a new . /// public ServicesModelBinder() : base(BindingSource.Services) { } /// protected override Task BindModelCoreAsync([NotNull] ModelBindingContext bindingContext) { var requestServices = bindingContext.OperationBindingContext.HttpContext.RequestServices; bindingContext.Model = requestServices.GetRequiredService(bindingContext.ModelType); return Task.FromResult(true); } } }