45 lines
1.7 KiB
C#
45 lines
1.7 KiB
C#
// 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.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNet.Mvc;
|
|
using Microsoft.AspNet.Routing;
|
|
using Microsoft.AspNet.Security;
|
|
using Microsoft.Framework.ConfigurationModel;
|
|
|
|
namespace Microsoft.Framework.DependencyInjection
|
|
{
|
|
public static class MvcServiceCollectionExtensions
|
|
{
|
|
public static IServiceCollection AddMvc([NotNull] this IServiceCollection services)
|
|
{
|
|
return AddMvc(services, configuration: null);
|
|
}
|
|
|
|
public static IServiceCollection AddMvc(
|
|
[NotNull] this IServiceCollection services,
|
|
IConfiguration configuration)
|
|
{
|
|
ConfigureDefaultServices(services, configuration);
|
|
services.TryAdd(MvcServices.GetDefaultServices(configuration));
|
|
return services;
|
|
}
|
|
|
|
private static void ConfigureDefaultServices(IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
services.AddOptions(configuration);
|
|
services.AddDataProtection(configuration);
|
|
services.AddRouting(configuration);
|
|
services.AddScopedInstance(configuration);
|
|
services.AddAuthorization(configuration);
|
|
services.Configure<RouteOptions>(routeOptions =>
|
|
routeOptions.ConstraintMap
|
|
.Add("exists",
|
|
typeof(KnownRouteValueConstraint)));
|
|
|
|
}
|
|
}
|
|
}
|