#122 - Rename IBuilder to IApplicationBuilder.
This commit is contained in:
parent
ba4f44c4ea
commit
335895d9b4
|
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Builder
|
|||
/// <param name="pathMatch">The path to match</param>
|
||||
/// <param name="configuration">The branch to take for positive path matches</param>
|
||||
/// <returns></returns>
|
||||
public static IBuilder Map([NotNull] this IBuilder app, [NotNull] string pathMatch, [NotNull] Action<IBuilder> configuration)
|
||||
public static IApplicationBuilder Map([NotNull] this IApplicationBuilder app, [NotNull] string pathMatch, [NotNull] Action<IApplicationBuilder> configuration)
|
||||
{
|
||||
return Map(app, new PathString(pathMatch), configuration);
|
||||
}
|
||||
|
|
@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Builder
|
|||
/// <param name="pathMatch">The path to match</param>
|
||||
/// <param name="configuration">The branch to take for positive path matches</param>
|
||||
/// <returns></returns>
|
||||
public static IBuilder Map([NotNull] this IBuilder app, PathString pathMatch, [NotNull] Action<IBuilder> configuration)
|
||||
public static IApplicationBuilder Map([NotNull] this IApplicationBuilder app, PathString pathMatch, [NotNull] Action<IApplicationBuilder> configuration)
|
||||
{
|
||||
if (pathMatch.HasValue && pathMatch.Value.EndsWith("/", StringComparison.Ordinal))
|
||||
{
|
||||
|
|
@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Builder
|
|||
}
|
||||
|
||||
// create branch
|
||||
IBuilder branchBuilder = app.New();
|
||||
var branchBuilder = app.New();
|
||||
configuration(branchBuilder);
|
||||
var branch = branchBuilder.Build();
|
||||
|
||||
|
|
|
|||
|
|
@ -23,10 +23,10 @@ namespace Microsoft.AspNet.Builder
|
|||
/// <param name="predicate">Invoked with the request environment to determine if the branch should be taken</param>
|
||||
/// <param name="configuration">Configures a branch to take</param>
|
||||
/// <returns></returns>
|
||||
public static IBuilder MapWhen([NotNull] this IBuilder app, [NotNull] Predicate predicate, [NotNull] Action<IBuilder> configuration)
|
||||
public static IApplicationBuilder MapWhen([NotNull] this IApplicationBuilder app, [NotNull] Predicate predicate, [NotNull] Action<IApplicationBuilder> configuration)
|
||||
{
|
||||
// create branch
|
||||
IBuilder branchBuilder = app.New();
|
||||
var branchBuilder = app.New();
|
||||
configuration(branchBuilder);
|
||||
var branch = branchBuilder.Build();
|
||||
|
||||
|
|
@ -46,10 +46,10 @@ namespace Microsoft.AspNet.Builder
|
|||
/// <param name="predicate">Invoked asynchronously with the request environment to determine if the branch should be taken</param>
|
||||
/// <param name="configuration">Configures a branch to take</param>
|
||||
/// <returns></returns>
|
||||
public static IBuilder MapWhenAsync([NotNull] this IBuilder app, [NotNull] PredicateAsync predicate, [NotNull] Action<IBuilder> configuration)
|
||||
public static IApplicationBuilder MapWhenAsync([NotNull] this IApplicationBuilder app, [NotNull] PredicateAsync predicate, [NotNull] Action<IApplicationBuilder> configuration)
|
||||
{
|
||||
// create branch
|
||||
IBuilder branchBuilder = app.New();
|
||||
var branchBuilder = app.New();
|
||||
configuration(branchBuilder);
|
||||
var branch = branchBuilder.Build();
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Builder
|
|||
{
|
||||
public static class RunExtensions
|
||||
{
|
||||
public static void Run([NotNull] this IBuilder app, [NotNull] RequestDelegate handler)
|
||||
public static void Run([NotNull] this IApplicationBuilder app, [NotNull] RequestDelegate handler)
|
||||
{
|
||||
app.Use(_ => handler);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace Microsoft.AspNet.Builder
|
|||
/// <param name="app"></param>
|
||||
/// <param name="middleware">A function that handles the request or calls the given next function.</param>
|
||||
/// <returns></returns>
|
||||
public static IBuilder Use(this IBuilder app, Func<HttpContext, Func<Task>, Task> middleware)
|
||||
public static IApplicationBuilder Use(this IApplicationBuilder app, Func<HttpContext, Func<Task>, Task> middleware)
|
||||
{
|
||||
return app.Use(next =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||
|
||||
namespace Microsoft.AspNet.Builder
|
||||
{
|
||||
public interface IBuilder
|
||||
public interface IApplicationBuilder
|
||||
{
|
||||
IServiceProvider ApplicationServices { get; set; }
|
||||
|
||||
|
|
@ -14,9 +14,9 @@ namespace Microsoft.AspNet.Builder
|
|||
|
||||
IDictionary<string, object> Properties { get; set; }
|
||||
|
||||
IBuilder Use(Func<RequestDelegate, RequestDelegate> middleware);
|
||||
IApplicationBuilder Use(Func<RequestDelegate, RequestDelegate> middleware);
|
||||
|
||||
IBuilder New();
|
||||
IApplicationBuilder New();
|
||||
|
||||
RequestDelegate Build();
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Builder
|
|||
|
||||
public static class OwinExtensions
|
||||
{
|
||||
public static AddMiddleware UseOwin(this IBuilder builder)
|
||||
public static AddMiddleware UseOwin(this IApplicationBuilder builder)
|
||||
{
|
||||
AddMiddleware add = middleware =>
|
||||
{
|
||||
|
|
@ -58,17 +58,17 @@ namespace Microsoft.AspNet.Builder
|
|||
return add;
|
||||
}
|
||||
|
||||
public static IBuilder UseOwin(this IBuilder builder, Action<AddMiddleware> pipeline)
|
||||
public static IApplicationBuilder UseOwin(this IApplicationBuilder builder, Action<AddMiddleware> pipeline)
|
||||
{
|
||||
pipeline(builder.UseOwin());
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static IBuilder UseBuilder(this AddMiddleware app)
|
||||
public static IApplicationBuilder UseBuilder(this AddMiddleware app)
|
||||
{
|
||||
// Adapt WebSockets by default.
|
||||
app(OwinWebSocketAcceptAdapter.AdaptWebSockets);
|
||||
var builder = new Builder(serviceProvider: null);
|
||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
||||
|
||||
CreateMiddleware middleware = CreateMiddlewareFactory(exit =>
|
||||
{
|
||||
|
|
@ -111,7 +111,7 @@ namespace Microsoft.AspNet.Builder
|
|||
};
|
||||
}
|
||||
|
||||
public static AddMiddleware UseBuilder(this AddMiddleware app, Action<IBuilder> pipeline)
|
||||
public static AddMiddleware UseBuilder(this AddMiddleware app, Action<IApplicationBuilder> pipeline)
|
||||
{
|
||||
var builder = app.UseBuilder();
|
||||
pipeline(builder);
|
||||
|
|
|
|||
|
|
@ -5,22 +5,21 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Infrastructure;
|
||||
|
||||
namespace Microsoft.AspNet.Builder
|
||||
{
|
||||
public class Builder : IBuilder
|
||||
public class ApplicationBuilder : IApplicationBuilder
|
||||
{
|
||||
private readonly IList<Func<RequestDelegate, RequestDelegate>> _components = new List<Func<RequestDelegate, RequestDelegate>>();
|
||||
|
||||
public Builder(IServiceProvider serviceProvider)
|
||||
public ApplicationBuilder(IServiceProvider serviceProvider)
|
||||
{
|
||||
Properties = new Dictionary<string, object>();
|
||||
ApplicationServices = serviceProvider;
|
||||
}
|
||||
|
||||
private Builder(Builder builder)
|
||||
private ApplicationBuilder(ApplicationBuilder builder)
|
||||
{
|
||||
Properties = builder.Properties;
|
||||
}
|
||||
|
|
@ -62,15 +61,15 @@ namespace Microsoft.AspNet.Builder
|
|||
Properties[key] = value;
|
||||
}
|
||||
|
||||
public IBuilder Use(Func<RequestDelegate, RequestDelegate> middleware)
|
||||
public IApplicationBuilder Use(Func<RequestDelegate, RequestDelegate> middleware)
|
||||
{
|
||||
_components.Add(middleware);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IBuilder New()
|
||||
public IApplicationBuilder New()
|
||||
{
|
||||
return new Builder(this);
|
||||
return new ApplicationBuilder(this);
|
||||
}
|
||||
|
||||
public RequestDelegate Build()
|
||||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Builder.Extensions
|
|||
{
|
||||
public class MapPathMiddlewareTests
|
||||
{
|
||||
private static readonly Action<IBuilder> ActionNotImplemented = new Action<IBuilder>(_ => { throw new NotImplementedException(); });
|
||||
private static readonly Action<IApplicationBuilder> ActionNotImplemented = new Action<IApplicationBuilder>(_ => { throw new NotImplementedException(); });
|
||||
|
||||
private static Task Success(HttpContext context)
|
||||
{
|
||||
|
|
@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Builder.Extensions
|
|||
return Task.FromResult<object>(null);
|
||||
}
|
||||
|
||||
private static void UseSuccess(IBuilder app)
|
||||
private static void UseSuccess(IApplicationBuilder app)
|
||||
{
|
||||
app.Run(Success);
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ namespace Microsoft.AspNet.Builder.Extensions
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private static void UseNotImplemented(IBuilder app)
|
||||
private static void UseNotImplemented(IApplicationBuilder app)
|
||||
{
|
||||
app.Run(NotImplemented);
|
||||
}
|
||||
|
|
@ -41,8 +41,8 @@ namespace Microsoft.AspNet.Builder.Extensions
|
|||
[Fact]
|
||||
public void NullArguments_ArgumentNullException()
|
||||
{
|
||||
var builder = new Builder(serviceProvider: null);
|
||||
var noMiddleware = new Builder(serviceProvider: null).Build();
|
||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
||||
var noMiddleware = new ApplicationBuilder(serviceProvider: null).Build();
|
||||
var noOptions = new MapOptions();
|
||||
// TODO: [NotNull] Assert.Throws<ArgumentNullException>(() => builder.Map(null, ActionNotImplemented));
|
||||
// TODO: [NotNull] Assert.Throws<ArgumentNullException>(() => builder.Map("/foo", (Action<IBuilder>)null));
|
||||
|
|
@ -61,7 +61,7 @@ namespace Microsoft.AspNet.Builder.Extensions
|
|||
public void PathMatchFunc_BranchTaken(string matchPath, string basePath, string requestPath)
|
||||
{
|
||||
HttpContext context = CreateRequest(basePath, requestPath);
|
||||
IBuilder builder = new Builder(serviceProvider: null);
|
||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
||||
builder.Map(matchPath, UseSuccess);
|
||||
var app = builder.Build();
|
||||
app.Invoke(context).Wait();
|
||||
|
|
@ -82,7 +82,7 @@ namespace Microsoft.AspNet.Builder.Extensions
|
|||
public void PathMatchAction_BranchTaken(string matchPath, string basePath, string requestPath)
|
||||
{
|
||||
HttpContext context = CreateRequest(basePath, requestPath);
|
||||
IBuilder builder = new Builder(serviceProvider: null);
|
||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
||||
builder.Map(matchPath, subBuilder => subBuilder.Run(Success));
|
||||
var app = builder.Build();
|
||||
app.Invoke(context).Wait();
|
||||
|
|
@ -98,7 +98,7 @@ namespace Microsoft.AspNet.Builder.Extensions
|
|||
[InlineData("/foo/cho/")]
|
||||
public void MatchPathWithTrailingSlashThrowsException(string matchPath)
|
||||
{
|
||||
Should.Throw<ArgumentException>(() => new Builder(serviceProvider: null).Map(matchPath, map => { }).Build());
|
||||
Should.Throw<ArgumentException>(() => new ApplicationBuilder(serviceProvider: null).Map(matchPath, map => { }).Build());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -112,7 +112,7 @@ namespace Microsoft.AspNet.Builder.Extensions
|
|||
public void PathMismatchFunc_PassedThrough(string matchPath, string basePath, string requestPath)
|
||||
{
|
||||
HttpContext context = CreateRequest(basePath, requestPath);
|
||||
IBuilder builder = new Builder(serviceProvider: null);
|
||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
||||
builder.Map(matchPath, UseNotImplemented);
|
||||
builder.Run(Success);
|
||||
var app = builder.Build();
|
||||
|
|
@ -134,7 +134,7 @@ namespace Microsoft.AspNet.Builder.Extensions
|
|||
public void PathMismatchAction_PassedThrough(string matchPath, string basePath, string requestPath)
|
||||
{
|
||||
HttpContext context = CreateRequest(basePath, requestPath);
|
||||
IBuilder builder = new Builder(serviceProvider: null);
|
||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
||||
builder.Map(matchPath, UseNotImplemented);
|
||||
builder.Run(Success);
|
||||
var app = builder.Build();
|
||||
|
|
@ -148,7 +148,7 @@ namespace Microsoft.AspNet.Builder.Extensions
|
|||
[Fact]
|
||||
public void ChainedRoutes_Success()
|
||||
{
|
||||
IBuilder builder = new Builder(serviceProvider: null);
|
||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
||||
builder.Map("/route1", map =>
|
||||
{
|
||||
map.Map((string)"/subroute1", UseSuccess);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Builder.Extensions
|
|||
return Task.FromResult<object>(null);
|
||||
}
|
||||
|
||||
private static void UseSuccess(IBuilder app)
|
||||
private static void UseSuccess(IApplicationBuilder app)
|
||||
{
|
||||
app.Run(Success);
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Builder.Extensions
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private static void UseNotImplemented(IBuilder app)
|
||||
private static void UseNotImplemented(IApplicationBuilder app)
|
||||
{
|
||||
app.Run(NotImplemented);
|
||||
}
|
||||
|
|
@ -64,8 +64,8 @@ namespace Microsoft.AspNet.Builder.Extensions
|
|||
[Fact]
|
||||
public void NullArguments_ArgumentNullException()
|
||||
{
|
||||
var builder = new Builder(serviceProvider: null);
|
||||
var noMiddleware = new Builder(serviceProvider: null).Build();
|
||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
||||
var noMiddleware = new ApplicationBuilder(serviceProvider: null).Build();
|
||||
var noOptions = new MapWhenOptions();
|
||||
// TODO: [NotNull] Assert.Throws<ArgumentNullException>(() => builder.MapWhen(null, UseNotImplemented));
|
||||
// TODO: [NotNull] Assert.Throws<ArgumentNullException>(() => builder.MapWhen(NotImplementedPredicate, (Action<IBuilder>)null));
|
||||
|
|
@ -82,7 +82,7 @@ namespace Microsoft.AspNet.Builder.Extensions
|
|||
public void PredicateTrue_BranchTaken()
|
||||
{
|
||||
HttpContext context = CreateRequest();
|
||||
IBuilder builder = new Builder(serviceProvider: null);
|
||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
||||
builder.MapWhen(TruePredicate, UseSuccess);
|
||||
var app = builder.Build();
|
||||
app.Invoke(context).Wait();
|
||||
|
|
@ -94,7 +94,7 @@ namespace Microsoft.AspNet.Builder.Extensions
|
|||
public void PredicateTrueAction_BranchTaken()
|
||||
{
|
||||
HttpContext context = CreateRequest();
|
||||
IBuilder builder = new Builder(serviceProvider: null);
|
||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
||||
builder.MapWhen(TruePredicate, UseSuccess);
|
||||
var app = builder.Build();
|
||||
app.Invoke(context).Wait();
|
||||
|
|
@ -106,7 +106,7 @@ namespace Microsoft.AspNet.Builder.Extensions
|
|||
public void PredicateFalseAction_PassThrough()
|
||||
{
|
||||
HttpContext context = CreateRequest();
|
||||
IBuilder builder = new Builder(serviceProvider: null);
|
||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
||||
builder.MapWhen(FalsePredicate, UseNotImplemented);
|
||||
builder.Run(Success);
|
||||
var app = builder.Build();
|
||||
|
|
@ -119,7 +119,7 @@ namespace Microsoft.AspNet.Builder.Extensions
|
|||
public void PredicateAsyncTrueAction_BranchTaken()
|
||||
{
|
||||
HttpContext context = CreateRequest();
|
||||
IBuilder builder = new Builder(serviceProvider: null);
|
||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
||||
builder.MapWhenAsync(TruePredicateAsync, UseSuccess);
|
||||
var app = builder.Build();
|
||||
app.Invoke(context).Wait();
|
||||
|
|
@ -131,7 +131,7 @@ namespace Microsoft.AspNet.Builder.Extensions
|
|||
public void PredicateAsyncFalseAction_PassThrough()
|
||||
{
|
||||
HttpContext context = CreateRequest();
|
||||
IBuilder builder = new Builder(serviceProvider: null);
|
||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
||||
builder.MapWhenAsync(FalsePredicateAsync, UseNotImplemented);
|
||||
builder.Run(Success);
|
||||
var app = builder.Build();
|
||||
|
|
@ -143,7 +143,7 @@ namespace Microsoft.AspNet.Builder.Extensions
|
|||
[Fact]
|
||||
public void ChainedPredicates_Success()
|
||||
{
|
||||
IBuilder builder = new Builder(serviceProvider: null);
|
||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
||||
builder.MapWhen(TruePredicate, map1 =>
|
||||
{
|
||||
map1.MapWhen((Predicate)FalsePredicate, UseNotImplemented);
|
||||
|
|
@ -160,7 +160,7 @@ namespace Microsoft.AspNet.Builder.Extensions
|
|||
[Fact]
|
||||
public void ChainedPredicatesAsync_Success()
|
||||
{
|
||||
IBuilder builder = new Builder(serviceProvider: null);
|
||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
||||
builder.MapWhenAsync(TruePredicateAsync, map1 =>
|
||||
{
|
||||
map1.MapWhenAsync((PredicateAsync)FalsePredicateAsync, UseNotImplemented);
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ using Xunit;
|
|||
|
||||
namespace Microsoft.AspNet.Builder.Tests
|
||||
{
|
||||
public class BuilderTests
|
||||
public class ApplicationBuilderTests
|
||||
{
|
||||
[Fact]
|
||||
public void BuildReturnsCallableDelegate()
|
||||
{
|
||||
var builder = new Builder(null);
|
||||
var builder = new ApplicationBuilder(null);
|
||||
var app = builder.Build();
|
||||
|
||||
var mockHttpContext = new Moq.Mock<HttpContext>();
|
||||
Loading…
Reference in New Issue