Files
Umbraco-CMS/src/Umbraco.Web.UI.NetCore/Startup.cs

101 lines
4.4 KiB
C#
Raw Normal View History

2020-02-18 08:32:06 +01:00
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
2020-03-16 14:02:08 +01:00
using Microsoft.Extensions.Configuration;
2020-02-18 08:32:06 +01:00
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Umbraco.Extensions;
2020-02-18 08:32:06 +01:00
namespace Umbraco.Web.UI.NetCore
2020-02-18 08:32:06 +01:00
{
public class Startup
{
private readonly IWebHostEnvironment _env;
private readonly IConfiguration _config;
/// <summary>
/// Constructor
/// </summary>
/// <param name="webHostEnvironment"></param>
/// <param name="config"></param>
/// <remarks>
/// Only a few services are possible to be injected here https://github.com/dotnet/aspnetcore/issues/9337
/// </remarks>
public Startup(IWebHostEnvironment webHostEnvironment, IConfiguration config)
{
_env = webHostEnvironment ?? throw new ArgumentNullException(nameof(webHostEnvironment));
_config = config ?? throw new ArgumentNullException(nameof(config));
}
2020-02-18 08:32:06 +01:00
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
2020-05-15 15:21:15 +01:00
{
// TODO: We will need to decide on if we want to use the ServiceBasedControllerActivator to create our controllers
// or use the default IControllerActivator: DefaultControllerActivator (which doesn't directly use the container to resolve controllers)
// This will affect whether we need to explicitly register controllers in the container like we do today in v8.
// What we absolutely must do though is make sure we explicitly opt-in to using one or the other *always* for our controllers instead of
// relying on a global configuration set by a user since if a custom IControllerActivator is used for our own controllers we may not
// guarantee it will work. And then... is that even possible?
// TODO: we will need to simplify this and prob just have a one or 2 main method that devs call which call all other required methods,
// but for now we'll just be explicit with all of them
services.AddUmbracoConfiguration(_config);
services.AddUmbracoCore(_env, out var factory);
services.AddUmbracoWebComponents();
services.AddUmbracoRuntimeMinifier(_config);
services.AddUmbracoBackOffice();
services.AddUmbracoBackOfficeIdentity();
services.AddMiniProfiler(options =>
{
options.ShouldProfile = request => false; // WebProfiler determine and start profiling. We should not use the MiniProfilerMiddleware to also profile
});
2020-04-01 14:19:41 +02:00
2020-06-11 11:21:07 +02:00
//We need to have runtime compilation of views when using umbraco. We could consider having only this when a specific config is set.
//But as far as I can see, there are still precompiled views, even when this is activated, so maybe it is okay.
services.AddControllersWithViews().AddRazorRuntimeCompilation();
// If using Kestrel: https://stackoverflow.com/a/55196057
services.Configure<KestrelServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
2020-08-18 11:36:45 +02:00
services.Configure<IISServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
2020-02-18 08:32:06 +01:00
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app)
2020-02-18 08:32:06 +01:00
{
//app.UseMiniProfiler();
if (_env.IsDevelopment())
2020-02-18 08:32:06 +01:00
{
app.UseDeveloperExceptionPage();
}
app.UseStatusCodePages();
app.UseRouting();
app.UseUmbracoCore();
app.UseUmbracoRouting();
app.UseRequestLocalization();
app.UseUmbracoRequestLogging();
2020-02-24 10:51:48 +01:00
app.UseUmbracoWebsite();
app.UseUmbracoBackOffice();
app.UseUmbracoInstaller();
2020-02-18 08:32:06 +01:00
app.UseEndpoints(endpoints =>
{
2020-05-07 15:24:46 +02:00
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
2020-02-18 08:32:06 +01:00
});
}
}
}