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

98 lines
3.6 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.Http;
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.Composing;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.IO;
2020-04-01 14:19:41 +02:00
using Umbraco.Core.Logging;
2020-02-18 08:32:06 +01:00
using Umbraco.Web.BackOffice.AspNetCore;
using Umbraco.Web.Common.AspNetCore;
using Umbraco.Web.Common.Extensions;
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
{
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)
{
services.AddUmbracoConfiguration(_config);
services.AddUmbracoRuntimeMinifier(_config);
services.AddUmbracoCore(_env, out var factory);
2020-02-24 10:51:48 +01:00
services.AddUmbracoWebsite();
services.AddMvc();
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
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.
public void Configure(IApplicationBuilder app)
2020-02-18 08:32:06 +01:00
{
// app.UseMiniProfiler();
app.UseUmbracoRequest();
if (_env.IsDevelopment())
2020-02-18 08:32:06 +01:00
{
app.UseDeveloperExceptionPage();
}
app.UseUmbracoCore();
2020-02-24 10:51:48 +01:00
app.UseUmbracoWebsite();
2020-02-18 08:32:06 +01:00
app.UseUmbracoBackOffice();
app.UseRouting();
app.UseUmbracoRuntimeMinification();
2020-02-18 08:32:06 +01:00
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute("Backoffice", "/umbraco/{Action}", new
{
Controller = "BackOffice",
Action = "Default"
});
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync($"<html><body>Hello World!{Current.Profiler.Render()}</body></html>");
});
2020-02-18 08:32:06 +01:00
});
}
}
}