2020-02-18 08:32:06 +01:00
using System ;
2020-04-28 07:01:30 +02:00
using System.Collections.Generic ;
2020-04-20 12:20:47 +02:00
using System.Data.Common ;
using System.Data.SqlClient ;
2020-05-06 20:37:03 +02:00
using System.IO ;
2020-04-27 10:09:10 +02:00
using System.Reflection ;
2020-02-18 08:32:06 +01:00
using Microsoft.AspNetCore.Builder ;
using Microsoft.AspNetCore.Hosting ;
using Microsoft.AspNetCore.Http ;
2020-04-20 12:20:47 +02:00
using Microsoft.AspNetCore.Mvc ;
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-04-20 12:20:47 +02:00
using Newtonsoft.Json.Serialization ;
2020-03-27 11:39:17 +01:00
using Umbraco.Composing ;
2020-03-29 22:35:52 +02:00
using Umbraco.Core ;
using Umbraco.Core.Configuration ;
using Umbraco.Core.IO ;
2020-04-01 14:19:41 +02:00
using Umbraco.Core.Logging ;
2020-04-28 07:01:30 +02:00
using Umbraco.Core.Persistence ;
using Umbraco.Core.Persistence.SqlSyntax ;
2020-02-18 08:32:06 +01:00
using Umbraco.Web.BackOffice.AspNetCore ;
2020-05-07 10:08:23 +02:00
using Umbraco.Extensions ;
2020-04-20 12:20:47 +02:00
using Umbraco.Web.Common.Filters ;
2020-02-24 10:51:48 +01:00
using Umbraco.Web.Website.AspNetCore ;
2020-04-01 14:19:41 +02:00
using IHostingEnvironment = Umbraco . Core . Hosting . IHostingEnvironment ;
2020-02-18 08:32:06 +01:00
namespace Umbraco.Web.UI.BackOffice
{
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-06 20:37:03 +02:00
services . AddUmbracoSqlCeSupport ( ) ;
services . AddUmbracoSqlServerSupport ( ) ;
2020-04-28 07:01:30 +02:00
2020-03-25 18:21:44 +11:00
services . AddUmbracoConfiguration ( _config ) ;
2020-03-26 06:51:23 +01:00
services . AddUmbracoRuntimeMinifier ( _config ) ;
2020-04-20 12:20:47 +02:00
2020-04-03 01:08:52 +11:00
services . AddUmbracoCore ( _env , out var factory ) ;
2020-02-24 10:51:48 +01:00
services . AddUmbracoWebsite ( ) ;
2020-03-30 21:27:35 +02:00
2020-04-20 12:20:47 +02:00
services . AddMvc ( options = >
{
options . Filters . Add < HttpResponseExceptionFilter > ( ) ;
2020-05-07 15:24:46 +02:00
2020-04-20 12:20:47 +02:00
} ) . SetCompatibilityVersion ( CompatibilityVersion . Version_3_0 )
. AddNewtonsoftJson ( options = >
{
options . SerializerSettings . ContractResolver = new CamelCasePropertyNamesContractResolver ( ) ;
} )
;
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
//Finally initialize Current
2020-04-22 14:23:56 +10:00
// TODO: This should be moved to the UmbracoServiceProviderFactory when the container is cross-wired and then don't use the overload above to `out var factory`
2020-04-01 14:19:41 +02:00
Current . Initialize (
factory . GetInstance < ILogger > ( ) ,
factory . GetInstance < Configs > ( ) ,
factory . GetInstance < IIOHelper > ( ) ,
factory . GetInstance < IHostingEnvironment > ( ) ,
factory . GetInstance < IBackOfficeInfo > ( ) ,
factory . GetInstance < IProfiler > ( )
) ;
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-03-29 22:35:52 +02:00
// app.UseMiniProfiler();
2020-03-24 18:18:25 +01:00
app . UseUmbracoRequest ( ) ;
2020-04-03 01:08:52 +11:00
if ( _env . IsDevelopment ( ) )
2020-02-18 08:32:06 +01:00
{
app . UseDeveloperExceptionPage ( ) ;
}
2020-04-21 10:55:01 +02:00
app . UseStatusCodePages ( ) ;
2020-03-27 11:39:17 +01:00
app . UseUmbracoCore ( ) ;
2020-04-22 14:23:56 +10:00
app . UseUmbracoRequestLogging ( ) ;
2020-02-24 10:51:48 +01:00
app . UseUmbracoWebsite ( ) ;
2020-02-18 08:32:06 +01:00
app . UseUmbracoBackOffice ( ) ;
app . UseRouting ( ) ;
2020-03-30 21:27:35 +02:00
app . UseUmbracoRuntimeMinification ( ) ;
2020-02-18 08:32:06 +01:00
app . UseEndpoints ( endpoints = >
{
2020-03-30 21:27:35 +02:00
endpoints . MapControllerRoute ( "Backoffice" , "/umbraco/{Action}" , new
{
Controller = "BackOffice" ,
Action = "Default"
} ) ;
2020-04-20 12:20:47 +02:00
endpoints . MapControllerRoute ( "Install" , "/install/{controller}/{Action}" , defaults : new { Area = "Install" } ) ;
//TODO register routing correct: Name must be like this
endpoints . MapControllerRoute ( "umbraco-api-UmbracoInstall-InstallApi" , "/install/api/{Action}" , defaults : new { Area = "Install" , Controller = "InstallApi" } ) ;
2020-05-07 15:24:46 +02:00
endpoints . MapControllerRoute (
name : "default" ,
pattern : "{controller}/{action=Index}/{id?}" ) ;
2020-03-27 11:39:17 +01:00
endpoints . MapGet ( "/" , async context = >
{
2020-04-22 15:23:51 +10:00
var profilerHtml = app . ApplicationServices . GetRequiredService < IProfilerHtml > ( ) ;
await context . Response . WriteAsync ( $"<html><body>Hello World!{profilerHtml.Render()}</body></html>" ) ;
2020-03-27 11:39:17 +01:00
} ) ;
2020-02-18 08:32:06 +01:00
} ) ;
}
}
}