diff --git a/src/Benchmarks/Middleware/FortunesDapperMiddleware.cs b/src/Benchmarks/Middleware/FortunesDapperMiddleware.cs index 06ec6b17d..67d87fcc1 100644 --- a/src/Benchmarks/Middleware/FortunesDapperMiddleware.cs +++ b/src/Benchmarks/Middleware/FortunesDapperMiddleware.cs @@ -2,15 +2,14 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Text.Encodings.Web; using System.Threading.Tasks; using Benchmarks.Configuration; using Benchmarks.Data; +using Benchmarks.Templates; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; -using RazorSlices; namespace Benchmarks.Middleware { @@ -20,13 +19,11 @@ public class FortunesDapperMiddleware private readonly RequestDelegate _next; private readonly HtmlEncoder _htmlEncoder; - private readonly SliceFactory> _fortunesFactory; public FortunesDapperMiddleware(RequestDelegate next, HtmlEncoder htmlEncoder) { _next = next; _htmlEncoder = htmlEncoder; - _fortunesFactory = RazorSlice.ResolveSliceFactory>("/Templates/FortunesUtf16.cshtml"); } public async Task Invoke(HttpContext httpContext) @@ -35,8 +32,9 @@ public async Task Invoke(HttpContext httpContext) { var db = httpContext.RequestServices.GetService(); var rows = await db.LoadFortunesRows(); + - await MiddlewareHelpers.RenderFortunesHtml(rows, httpContext, _htmlEncoder, _fortunesFactory); + await MiddlewareHelpers.RenderFortunesHtml(rows, httpContext, _htmlEncoder, FortunesUtf16.Create); return; } diff --git a/src/Benchmarks/Middleware/FortunesEfMiddleware.cs b/src/Benchmarks/Middleware/FortunesEfMiddleware.cs index 049ef306e..05808feda 100644 --- a/src/Benchmarks/Middleware/FortunesEfMiddleware.cs +++ b/src/Benchmarks/Middleware/FortunesEfMiddleware.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Text.Encodings.Web; using System.Threading.Tasks; using Benchmarks.Configuration; @@ -10,7 +9,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; -using RazorSlices; namespace Benchmarks.Middleware { @@ -20,13 +18,11 @@ public class FortunesEfMiddleware private readonly RequestDelegate _next; private readonly HtmlEncoder _htmlEncoder; - private readonly SliceFactory> _fortunesFactory; public FortunesEfMiddleware(RequestDelegate next, HtmlEncoder htmlEncoder) { _next = next; _htmlEncoder = htmlEncoder; - _fortunesFactory = RazorSlice.ResolveSliceFactory>("/Templates/Fortunes.cshtml"); } public async Task Invoke(HttpContext httpContext) @@ -36,7 +32,7 @@ public async Task Invoke(HttpContext httpContext) var db = httpContext.RequestServices.GetService(); var rows = await db.LoadFortunesRows(); - await MiddlewareHelpers.RenderFortunesHtml(rows, httpContext, _htmlEncoder, _fortunesFactory); + await MiddlewareHelpers.RenderFortunesHtml(rows, httpContext, _htmlEncoder, Templates.Fortunes.Create); return; } diff --git a/src/Benchmarks/Middleware/FortunesRawMiddleware.cs b/src/Benchmarks/Middleware/FortunesRawMiddleware.cs index 7124a78d4..de3aee470 100644 --- a/src/Benchmarks/Middleware/FortunesRawMiddleware.cs +++ b/src/Benchmarks/Middleware/FortunesRawMiddleware.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Text.Encodings.Web; using System.Threading.Tasks; using Benchmarks.Configuration; @@ -10,7 +9,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; -using RazorSlices; namespace Benchmarks.Middleware { @@ -20,13 +18,11 @@ public class FortunesRawMiddleware private readonly RequestDelegate _next; private readonly HtmlEncoder _htmlEncoder; - private readonly SliceFactory> _fortunesFactory; public FortunesRawMiddleware(RequestDelegate next, HtmlEncoder htmlEncoder) { _next = next; _htmlEncoder = htmlEncoder; - _fortunesFactory = RazorSlice.ResolveSliceFactory>("/Templates/Fortunes.cshtml"); } public async Task Invoke(HttpContext httpContext) @@ -36,7 +32,7 @@ public async Task Invoke(HttpContext httpContext) var db = httpContext.RequestServices.GetService(); var rows = await db.LoadFortunesRows(); - await MiddlewareHelpers.RenderFortunesHtml(rows, httpContext, _htmlEncoder, _fortunesFactory); + await MiddlewareHelpers.RenderFortunesHtml(rows, httpContext, _htmlEncoder, Templates.Fortunes.Create); return; } diff --git a/src/Benchmarks/Middleware/FortunesRawSyncMiddleware.cs b/src/Benchmarks/Middleware/FortunesRawSyncMiddleware.cs index 765a79840..ec3ef495b 100644 --- a/src/Benchmarks/Middleware/FortunesRawSyncMiddleware.cs +++ b/src/Benchmarks/Middleware/FortunesRawSyncMiddleware.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Text.Encodings.Web; using System.Threading.Tasks; using Benchmarks.Configuration; @@ -10,7 +9,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; -using RazorSlices; namespace Benchmarks.Middleware { @@ -20,13 +18,11 @@ public class FortunesRawSyncMiddleware private readonly RequestDelegate _next; private readonly HtmlEncoder _htmlEncoder; - private readonly SliceFactory> _fortunesFactory; public FortunesRawSyncMiddleware(RequestDelegate next, HtmlEncoder htmlEncoder) { _next = next; _htmlEncoder = htmlEncoder; - _fortunesFactory = RazorSlice.ResolveSliceFactory>("/Templates/Fortunes.cshtml"); } public Task Invoke(HttpContext httpContext) @@ -36,7 +32,7 @@ public Task Invoke(HttpContext httpContext) var db = httpContext.RequestServices.GetService(); var rows = db.LoadFortunesRowsSync(); - return MiddlewareHelpers.RenderFortunesHtml(rows, httpContext, _htmlEncoder, _fortunesFactory); + return MiddlewareHelpers.RenderFortunesHtml(rows, httpContext, _htmlEncoder, Templates.Fortunes.Create); } return _next(httpContext); diff --git a/src/Benchmarks/Middleware/MiddlewareHelpers.cs b/src/Benchmarks/Middleware/MiddlewareHelpers.cs index 3b8ee4107..f46b66a91 100644 --- a/src/Benchmarks/Middleware/MiddlewareHelpers.cs +++ b/src/Benchmarks/Middleware/MiddlewareHelpers.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using System.Text.Encodings.Web; using System.Threading.Tasks; @@ -30,13 +31,13 @@ public static int GetMultipleQueriesQueryCount(HttpContext httpContext) } public static async Task RenderFortunesHtml(IEnumerable model, HttpContext httpContext, - HtmlEncoder htmlEncoder, SliceFactory> fortunesFactory) + HtmlEncoder htmlEncoder, Func, RazorSlice> templateFactory) { httpContext.Response.StatusCode = StatusCodes.Status200OK; httpContext.Response.ContentType = "text/html; charset=UTF-8"; - using var template = fortunesFactory(model); - await template.RenderToPipeWriterAsync(httpContext.Response.BodyWriter, htmlEncoder); + using var template = templateFactory(model); + await template.RenderAsync(httpContext.Response.BodyWriter, htmlEncoder); await httpContext.Response.BodyWriter.FlushAsync(); } }