33| Client Ignia, LLC
44| Project Sample OnTopic Site
55\=============================================================================================================================*/
6- using System . Diagnostics . CodeAnalysis ;
7-
8- namespace OnTopic . AspNetCore . Mvc . Host {
9-
10- /*============================================================================================================================
11- | CLASS: PROGRAM
12- \---------------------------------------------------------------------------------------------------------------------------*/
13- /// <summary>
14- /// The <see cref="Program"/> class—and its <see cref="Program.Main(String[])"/> method—represent the entry point into the
15- /// ASP.NET Core web application.
16- /// </summary>
17- [ ExcludeFromCodeCoverage ]
18- public static class Program {
19-
20- /*==========================================================================================================================
21- | METHOD: MAIN
22- \-------------------------------------------------------------------------------------------------------------------------*/
23- /// <summary>
24- /// Responsible for bootstrapping the web application.
25- /// </summary>
26- public static void Main ( string [ ] args ) => CreateHostBuilder ( args ) . Build ( ) . Run ( ) ;
27-
28- /*==========================================================================================================================
29- | METHOD: CREATE WEB HOST BUILDER
30- \-------------------------------------------------------------------------------------------------------------------------*/
31- /// <summary>
32- /// Configures a new <see cref="IWebHostBuilder"/> with the default options.
33- /// </summary>
34- public static IHostBuilder CreateHostBuilder ( string [ ] args ) =>
35- Microsoft . Extensions . Hosting . Host
36- . CreateDefaultBuilder ( args )
37- . ConfigureWebHostDefaults ( webBuilder => {
38- webBuilder . UseStartup < Startup > ( ) ;
39- } ) ;
40-
41- } //Class
42- } //Namespace
6+ using Microsoft . AspNetCore . Mvc . Controllers ;
7+ using Microsoft . AspNetCore . Mvc . ViewComponents ;
8+ using OnTopic . AspNetCore . Mvc ;
9+ using OnTopic . AspNetCore . Mvc . Host ;
10+
11+ #pragma warning disable CA1812 // Avoid uninstantiated internal classes
12+
13+ /*==============================================================================================================================
14+ | CONFIGURE SERVICES
15+ \-----------------------------------------------------------------------------------------------------------------------------*/
16+ var builder = WebApplication . CreateBuilder ( args ) ;
17+
18+ /*------------------------------------------------------------------------------------------------------------------------------
19+ | Configure: Cookie Policy
20+ \-----------------------------------------------------------------------------------------------------------------------------*/
21+ builder . Services . Configure < CookiePolicyOptions > ( options => {
22+ // This lambda determines whether user consent for non-essential cookies is needed for a given request.
23+ options . CheckConsentNeeded = context => true ;
24+ options . MinimumSameSitePolicy = SameSiteMode . None ;
25+ } ) ;
26+
27+ /*------------------------------------------------------------------------------------------------------------------------------
28+ | Configure: MVC
29+ \-----------------------------------------------------------------------------------------------------------------------------*/
30+ builder . Services . AddControllersWithViews ( )
31+
32+ //Add OnTopic support
33+ . AddTopicSupport ( ) ;
34+
35+ /*------------------------------------------------------------------------------------------------------------------------------
36+ | Register: Activators
37+ \-----------------------------------------------------------------------------------------------------------------------------*/
38+ var activator = new SampleActivator ( builder . Configuration . GetConnectionString ( "OnTopic" ) ) ;
39+
40+ builder . Services . AddSingleton < IControllerActivator > ( activator ) ;
41+ builder . Services . AddSingleton < IViewComponentActivator > ( activator ) ;
42+
43+ /*==============================================================================================================================
44+ | CONFIGURE APPLICATION
45+ \-----------------------------------------------------------------------------------------------------------------------------*/
46+ var app = builder . Build ( ) ;
47+
48+ /*------------------------------------------------------------------------------------------------------------------------------
49+ | Configure: Error Pages
50+ \-----------------------------------------------------------------------------------------------------------------------------*/
51+ if ( app . Environment . IsDevelopment ( ) ) {
52+ app . UseDeveloperExceptionPage ( ) ;
53+ }
54+ else {
55+ app . UseExceptionHandler ( "/Home/Error" ) ;
56+ // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
57+ app . UseHsts ( ) ;
58+ }
59+
60+ /*------------------------------------------------------------------------------------------------------------------------------
61+ | Configure: Server defaults
62+ \-----------------------------------------------------------------------------------------------------------------------------*/
63+ app . UseHttpsRedirection ( ) ;
64+ app . UseStaticFiles ( ) ;
65+ app . UseCookiePolicy ( ) ;
66+ app . UseRouting ( ) ;
67+ app . UseCors ( "default" ) ;
68+
69+ /*------------------------------------------------------------------------------------------------------------------------------
70+ | Configure: MVC
71+ \-----------------------------------------------------------------------------------------------------------------------------*/
72+ app . MapTopicRoute ( "Web" ) ;
73+ app . MapTopicSitemap ( ) ;
74+ app . MapTopicRedirect ( ) ;
75+ app . MapControllers ( ) ;
76+
77+ /*------------------------------------------------------------------------------------------------------------------------------
78+ | Run application
79+ \-----------------------------------------------------------------------------------------------------------------------------*/
80+ app . Run ( ) ;
81+
82+ #pragma warning restore CA1812 // Avoid uninstantiated internal classes
0 commit comments