GetDefaultServices -> AddRouting with TryAdd
This commit is contained in:
parent
1f67f69205
commit
21a6f44c38
|
|
@ -15,7 +15,7 @@ namespace RoutingSample.Web
|
|||
{
|
||||
builder.UseServices(services =>
|
||||
{
|
||||
services.Add(RoutingServices.GetDefaultServices());
|
||||
services.AddRouting();
|
||||
});
|
||||
|
||||
var endpoint1 = new DelegateRouteEndpoint(async (context) =>
|
||||
|
|
|
|||
|
|
@ -1,24 +1,18 @@
|
|||
// 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 Microsoft.Framework.ConfigurationModel;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
|
||||
namespace Microsoft.AspNet.Routing
|
||||
{
|
||||
public class RoutingServices
|
||||
public static class RoutingServices
|
||||
{
|
||||
public static IEnumerable<IServiceDescriptor> GetDefaultServices()
|
||||
public static IServiceCollection AddRouting(this IServiceCollection services, IConfiguration config = null)
|
||||
{
|
||||
return GetDefaultServices(new Configuration());
|
||||
}
|
||||
|
||||
public static IEnumerable<IServiceDescriptor> GetDefaultServices(IConfiguration configuration)
|
||||
{
|
||||
var describe = new ServiceDescriber(configuration);
|
||||
|
||||
yield return describe.Transient<IInlineConstraintResolver, DefaultInlineConstraintResolver>();
|
||||
var describe = new ServiceDescriber(config);
|
||||
services.TryAdd(describe.Transient<IInlineConstraintResolver, DefaultInlineConstraintResolver>());
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -293,7 +293,7 @@ namespace Microsoft.AspNet.Routing.Tests
|
|||
|
||||
private static IInlineConstraintResolver GetConstraintResolver()
|
||||
{
|
||||
var services = new ServiceCollection { OptionsServices.GetDefaultServices() };
|
||||
var services = new ServiceCollection().AddOptions();
|
||||
services.Configure<RouteOptions>(options =>
|
||||
options
|
||||
.ConstraintMap
|
||||
|
|
|
|||
|
|
@ -1054,7 +1054,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests
|
|||
|
||||
private static IInlineConstraintResolver GetInlineConstraintResolver()
|
||||
{
|
||||
var services = new ServiceCollection { OptionsServices.GetDefaultServices() };
|
||||
var services = new ServiceCollection().AddOptions();
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
var accessor = serviceProvider.GetRequiredService<IOptions<RouteOptions>>();
|
||||
return new DefaultInlineConstraintResolver(serviceProvider, accessor);
|
||||
|
|
|
|||
|
|
@ -829,7 +829,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests
|
|||
|
||||
private static IInlineConstraintResolver GetInlineConstraintResolver()
|
||||
{
|
||||
var services = new ServiceCollection { OptionsServices.GetDefaultServices() };
|
||||
var services = new ServiceCollection().AddOptions();
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
var accessor = serviceProvider.GetRequiredService<IOptions<RouteOptions>>();
|
||||
return new DefaultInlineConstraintResolver(serviceProvider, accessor);
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ namespace Microsoft.AspNet.Routing.Tests
|
|||
|
||||
private static IInlineConstraintResolver GetInlineConstraintResolver()
|
||||
{
|
||||
var services = new ServiceCollection { OptionsServices.GetDefaultServices() };
|
||||
var services = new ServiceCollection().AddOptions();
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
var accessor = serviceProvider.GetRequiredService<IOptions<RouteOptions>>();
|
||||
return new DefaultInlineConstraintResolver(serviceProvider, accessor);
|
||||
|
|
|
|||
Loading…
Reference in New Issue