React to GetDefaultServices/TryAdd changes

This commit is contained in:
Hao Kung 2014-11-24 16:38:45 -08:00
parent e7941b5a84
commit 27432d9453
3 changed files with 12 additions and 22 deletions

View File

@ -10,22 +10,19 @@ namespace Microsoft.Framework.DependencyInjection
{
public static class MvcServiceCollectionExtensions
{
public static IServiceCollection AddMvc(this IServiceCollection services)
public static IServiceCollection AddMvc(this IServiceCollection services, IConfiguration configuration = null)
{
ConfigureDefaultServices(services);
return services.Add(MvcServices.GetDefaultServices());
ConfigureDefaultServices(services, configuration);
services.TryAdd(MvcServices.GetDefaultServices(configuration));
return services;
}
public static IServiceCollection AddMvc(this IServiceCollection services, IConfiguration configuration)
private static void ConfigureDefaultServices(IServiceCollection services, IConfiguration configuration)
{
ConfigureDefaultServices(services);
return services.Add(MvcServices.GetDefaultServices(configuration));
}
private static void ConfigureDefaultServices(IServiceCollection services)
{
services.Add(DataProtectionServices.GetDefaultServices());
services.Add(RoutingServices.GetDefaultServices());
services.AddOptions(configuration);
services.AddDataProtection(configuration);
services.AddRouting(configuration);
services.AddContextAccessor(configuration);
services.Configure<RouteOptions>(routeOptions =>
routeOptions.ConstraintMap
.Add("exists",

View File

@ -23,12 +23,7 @@ namespace Microsoft.AspNet.Mvc
{
public class MvcServices
{
public static IEnumerable<IServiceDescriptor> GetDefaultServices()
{
return GetDefaultServices(new Configuration());
}
public static IEnumerable<IServiceDescriptor> GetDefaultServices(IConfiguration configuration)
public static IEnumerable<IServiceDescriptor> GetDefaultServices(IConfiguration configuration = null)
{
var describe = new ServiceDescriber(configuration);

View File

@ -12,7 +12,6 @@ using Microsoft.CodeAnalysis.CSharp;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Microsoft.Framework.DependencyInjection.ServiceLookup;
using Microsoft.Framework.OptionsModel;
using Microsoft.Framework.Runtime;
namespace Microsoft.AspNet.Mvc
@ -33,10 +32,9 @@ namespace Microsoft.AspNet.Mvc
var appEnv = _appServices.GetRequiredService<IApplicationEnvironment>();
var setup = new RazorViewEngineOptionsSetup(appEnv);
var accessor = new OptionsManager<RazorViewEngineOptions>(new[] { setup });
var sc = new ServiceCollection();
sc.AddInstance<IOptions<RazorViewEngineOptions>>(accessor);
sc.Add(MvcServices.GetDefaultServices());
sc.ConfigureOptions(setup);
sc.AddMvc();
var viewCompiler = new RazorPreCompiler(BuildFallbackServiceProvider(sc, _appServices));
viewCompiler.CompileViews(context);