using System; using System.Collections.Generic; using System.Data.Common; using System.Data.SqlClient; using System.IO; using System.Reflection; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Newtonsoft.Json.Serialization; using Umbraco.Composing; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Web.BackOffice.AspNetCore; using Umbraco.Extensions; using Umbraco.Web.Common.Filters; using Umbraco.Web.Website.AspNetCore; using IHostingEnvironment = Umbraco.Core.Hosting.IHostingEnvironment; namespace Umbraco.Web.UI.BackOffice { public class Startup { private readonly IWebHostEnvironment _env; private readonly IConfiguration _config; /// /// Constructor /// /// /// /// /// Only a few services are possible to be injected here https://github.com/dotnet/aspnetcore/issues/9337 /// public Startup(IWebHostEnvironment webHostEnvironment, IConfiguration config) { _env = webHostEnvironment ?? throw new ArgumentNullException(nameof(webHostEnvironment)); _config = config ?? throw new ArgumentNullException(nameof(config)); } // 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) { services.AddUmbracoSqlCeSupport(); services.AddUmbracoSqlServerSupport(); services.AddUmbracoConfiguration(_config); services.AddUmbracoRuntimeMinifier(_config); services.AddUmbracoCore(_env, out var factory); services.AddUmbracoWebsite(); services.AddMvc(options => { options.Filters.Add(); }).SetCompatibilityVersion(CompatibilityVersion.Version_3_0) .AddNewtonsoftJson(options => { options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); }) ; services.AddMiniProfiler(options => { options.ShouldProfile = request => false; // WebProfiler determine and start profiling. We should not use the MiniProfilerMiddleware to also profile }); //Finally initialize Current // 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` Current.Initialize( factory.GetInstance (), factory.GetInstance(), factory.GetInstance(), factory.GetInstance(), factory.GetInstance(), factory.GetInstance() ); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app) { // app.UseMiniProfiler(); app.UseUmbracoRequest(); if (_env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseStatusCodePages(); app.UseUmbracoCore(); app.UseUmbracoRequestLogging(); app.UseUmbracoWebsite(); app.UseUmbracoBackOffice(); app.UseRouting(); app.UseUmbracoRuntimeMinification(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute("Backoffice", "/umbraco/{Action}", new { Controller = "BackOffice", Action = "Default" }); 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"}); endpoints.MapControllerRoute( name: "default", pattern: "{controller}/{action=Index}/{id?}"); endpoints.MapGet("/", async context => { var profilerHtml = app.ApplicationServices.GetRequiredService(); await context.Response.WriteAsync($"Hello World!{profilerHtml.Render()}"); }); }); } } }