33 lines
1.4 KiB
C#
33 lines
1.4 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 Microsoft.AspNet.Mvc;
|
|
using Microsoft.AspNet.Routing;
|
|
using Microsoft.AspNet.Security.DataProtection;
|
|
using Microsoft.Framework.ConfigurationModel;
|
|
|
|
namespace Microsoft.Framework.DependencyInjection
|
|
{
|
|
public static class MvcServiceCollectionExtensions
|
|
{
|
|
public static IServiceCollection AddMvc(this IServiceCollection services, IConfiguration configuration = null)
|
|
{
|
|
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.AddContextAccessor(configuration);
|
|
services.Configure<RouteOptions>(routeOptions =>
|
|
routeOptions.ConstraintMap
|
|
.Add("exists",
|
|
typeof(KnownRouteValueConstraint)));
|
|
}
|
|
}
|
|
}
|