// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ActionConstraints
{
///
/// A default implementation of .
///
///
/// This provider is able to provide an instance when the
/// implements or
/// /
///
public class DefaultActionConstraintProvider : IActionConstraintProvider
{
///
public int Order
{
get { return DefaultOrder.DefaultFrameworkSortOrder; }
}
///
public void OnProvidersExecuting([NotNull] ActionConstraintProviderContext context)
{
foreach (var item in context.Results)
{
ProvideConstraint(item, context.HttpContext.RequestServices);
}
}
///
public void OnProvidersExecuted([NotNull] ActionConstraintProviderContext context)
{
}
private void ProvideConstraint(ActionConstraintItem item, IServiceProvider services)
{
// Don't overwrite anything that was done by a previous provider.
if (item.Constraint != null)
{
return;
}
var constraint = item.Metadata as IActionConstraint;
if (constraint != null)
{
item.Constraint = constraint;
return;
}
var factory = item.Metadata as IActionConstraintFactory;
if (factory != null)
{
item.Constraint = factory.CreateInstance(services);
return;
}
}
}
}