React to GetDefaultServices/TryAdd changes
This commit is contained in:
parent
e7941b5a84
commit
27432d9453
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue