Last active
July 2, 2021 20:45
-
-
Save crgrieve/9e73646f9f4c54f934b1cc654b6472f0 to your computer and use it in GitHub Desktop.
An example Startup.cs for Umbraco v9 project with some usings refactored to a global file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Builder; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Umbraco.Cms.Core.DependencyInjection; | |
using Umbraco.Extensions; | |
namespace DotNet6Umbraco | |
{ | |
public class Startup | |
{ | |
private readonly IWebHostEnvironment _env; | |
private readonly IConfiguration _config; | |
/// <summary> | |
/// Initializes a new instance of the <see cref="Startup"/> class. | |
/// </summary> | |
/// <param name="webHostEnvironment">The Web Host Environment</param> | |
/// <param name="config">The Configuration</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)); | |
} | |
/// <summary> | |
/// Configures the services | |
/// </summary> | |
/// <remarks> | |
/// 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 | |
/// </remarks> | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddUmbraco(_env, _config) | |
.AddBackOffice() | |
.AddWebsite() | |
.AddComposers() | |
.Build(); | |
} | |
/// <summary> | |
/// Configures the application | |
/// </summary> | |
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
if (env.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
} | |
app.UseUmbraco() | |
.WithMiddleware(u => | |
{ | |
u.WithBackOffice(); | |
u.WithWebsite(); | |
}) | |
.WithEndpoints(u => | |
{ | |
u.UseInstallerEndpoints(); | |
u.UseBackOfficeEndpoints(); | |
u.UseWebsiteEndpoints(); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment