2020-02-18 08:32:06 +01:00
|
|
|
using System;
|
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2020-05-11 16:23:33 +02:00
|
|
|
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;
|
2020-05-07 10:08:23 +02:00
|
|
|
using Umbraco.Extensions;
|
2020-02-18 08:32:06 +01:00
|
|
|
|
2020-08-11 08:28:16 +02:00
|
|
|
namespace Umbraco.Web.UI.NetCore
|
2020-02-18 08:32:06 +01:00
|
|
|
{
|
|
|
|
|
public class Startup
|
|
|
|
|
{
|
2020-04-03 01:08:52 +11:00
|
|
|
private readonly IWebHostEnvironment _env;
|
2020-03-25 18:21:44 +11:00
|
|
|
private readonly IConfiguration _config;
|
2020-03-25 20:42:02 +01:00
|
|
|
|
2020-03-25 18:21:44 +11:00
|
|
|
/// <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)
|
2020-03-25 20:42:02 +01:00
|
|
|
{
|
2020-04-03 01:08:52 +11:00
|
|
|
_env = webHostEnvironment ?? throw new ArgumentNullException(nameof(webHostEnvironment));
|
2020-03-25 18:21:44 +11:00
|
|
|
_config = config ?? throw new ArgumentNullException(nameof(config));
|
2020-03-25 20:42:02 +01:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
2020-05-14 17:04:16 +10: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?
|
|
|
|
|
|
2020-05-26 22:21:22 +10:00
|
|
|
// 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
|
2020-03-25 18:21:44 +11:00
|
|
|
services.AddUmbracoConfiguration(_config);
|
2020-04-03 01:08:52 +11:00
|
|
|
services.AddUmbracoCore(_env, out var factory);
|
2020-05-12 10:21:40 +10:00
|
|
|
services.AddUmbracoWebComponents();
|
2020-05-08 16:35:37 +10:00
|
|
|
services.AddUmbracoRuntimeMinifier(_config);
|
2020-05-26 22:21:22 +10:00
|
|
|
services.AddUmbracoBackOffice();
|
2020-05-17 10:39:30 +01:00
|
|
|
services.AddUmbracoBackOfficeIdentity();
|
2020-03-29 22:35:52 +02:00
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
|
2020-05-11 16:23:33 +02:00
|
|
|
// 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.
|
2020-04-03 01:08:52 +11:00
|
|
|
public void Configure(IApplicationBuilder app)
|
2020-02-18 08:32:06 +01:00
|
|
|
{
|
2020-05-18 11:51:55 +02:00
|
|
|
//app.UseMiniProfiler();
|
2020-04-03 01:08:52 +11:00
|
|
|
if (_env.IsDevelopment())
|
2020-02-18 08:32:06 +01:00
|
|
|
{
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
}
|
2020-05-12 10:21:40 +10:00
|
|
|
|
2020-04-21 10:55:01 +02:00
|
|
|
app.UseStatusCodePages();
|
2020-05-12 10:21:40 +10:00
|
|
|
app.UseRouting();
|
|
|
|
|
|
2020-03-27 11:39:17 +01:00
|
|
|
app.UseUmbracoCore();
|
2020-05-12 15:18:55 +10:00
|
|
|
app.UseUmbracoRouting();
|
2020-08-04 12:54:54 +02:00
|
|
|
app.UseRequestLocalization();
|
2020-04-22 14:23:56 +10:00
|
|
|
app.UseUmbracoRequestLogging();
|
2020-02-24 10:51:48 +01:00
|
|
|
app.UseUmbracoWebsite();
|
2020-05-12 15:18:55 +10:00
|
|
|
app.UseUmbracoBackOffice();
|
|
|
|
|
app.UseUmbracoInstaller();
|
2020-05-18 11:51:55 +02:00
|
|
|
|
2020-02-18 08:32:06 +01:00
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
|
|
{
|
2020-05-07 15:24:46 +02:00
|
|
|
endpoints.MapControllerRoute(
|
|
|
|
|
name: "default",
|
2020-05-18 11:51:55 +02:00
|
|
|
pattern: "{controller}/{action=Index}/{id?}");
|
2020-02-18 08:32:06 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|