Getting front end routing poc going

This commit is contained in:
Shannon
2020-12-08 16:33:50 +11:00
parent 7e4a6421d6
commit e3be4009c0
37 changed files with 543 additions and 315 deletions

View File

@@ -1,14 +1,21 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Umbraco.Core.DependencyInjection;
using Umbraco.Core.DependencyInjection;
using Umbraco.Web.Website.Controllers;
using Umbraco.Web.Website.Routing;
using Umbraco.Web.Website.ViewEngines;
namespace Umbraco.Extensions
{
/// <summary>
/// <see cref="IUmbracoBuilder"/> extensions for umbraco front-end website
/// </summary>
public static class UmbracoBuilderExtensions
{
/// <summary>
/// Add services for the umbraco front-end website
/// </summary>
public static IUmbracoBuilder AddUmbracoWebsite(this IUmbracoBuilder builder)
{
// Set the render & plugin view engines (Super complicated, but this allows us to use the IServiceCollection
@@ -21,12 +28,14 @@ namespace Umbraco.Extensions
// Wraps all existing view engines in a ProfilerViewEngine
builder.Services.AddTransient<IConfigureOptions<MvcViewOptions>, ProfilingViewEngineWrapperMvcViewOptionsSetup>();
//TODO figure out if we need more to work on load balanced setups
// TODO figure out if we need more to work on load balanced setups
builder.Services.AddDataProtection();
builder.Services.AddScoped<UmbracoRouteValueTransformer>();
builder.Services.AddSingleton<IUmbracoRenderingDefaults, UmbracoRenderingDefaults>();
return builder;
}
}
}

View File

@@ -6,28 +6,41 @@ using Umbraco.Web.Website.Routing;
namespace Umbraco.Extensions
{
/// <summary>
/// <see cref="IApplicationBuilder"/> extensions for the umbraco front-end website
/// </summary>
public static class UmbracoWebsiteApplicationBuilderExtensions
{
/// <summary>
/// Sets up services and routes for the front-end umbraco website
/// </summary>
public static IApplicationBuilder UseUmbracoWebsite(this IApplicationBuilder app)
{
if (app == null) throw new ArgumentNullException(nameof(app));
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (!app.UmbracoCanBoot()) return app;
if (!app.UmbracoCanBoot())
{
return app;
}
// Important we handle image manipulations before the static files, otherwise the querystring is just ignored.
// TODO: Since we are dependent on these we need to register them but what happens when we call this multiple times since we are dependent on this for UseUmbracoBackOffice too?
app.UseImageSharp();
app.UseStaticFiles();
app.UseUmbracoNoContentPage();
app.UseUmbracoRoutes();
return app;
}
public static IApplicationBuilder UseUmbracoNoContentPage(this IApplicationBuilder app)
/// <summary>
/// Sets up routes for the umbraco front-end
/// </summary>
public static IApplicationBuilder UseUmbracoRoutes(this IApplicationBuilder app)
{
app.UseEndpoints(endpoints =>
{
var noContentRoutes = app.ApplicationServices.GetRequiredService<NoContentRoutes>();
endpoints.MapDynamicControllerRoute<UmbracoRouteValueTransformer>("/{**slug}");
NoContentRoutes noContentRoutes = app.ApplicationServices.GetRequiredService<NoContentRoutes>();
noContentRoutes.CreateRoutes(endpoints);
});