GetDefaultServices -> AddRouting with TryAdd

This commit is contained in:
Hao Kung 2014-11-24 09:52:14 -08:00
parent 1f67f69205
commit 21a6f44c38
6 changed files with 10 additions and 16 deletions

View File

@ -15,7 +15,7 @@ namespace RoutingSample.Web
{
builder.UseServices(services =>
{
services.Add(RoutingServices.GetDefaultServices());
services.AddRouting();
});
var endpoint1 = new DelegateRouteEndpoint(async (context) =>

View File

@ -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;
}
}
}

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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);