Pārlūkot izejas kodu

Updated to .NET 6 and AspNetCore 6.1.0-beta1

Lukas Angerer 4 gadi atpakaļ
vecāks
revīzija
c244cd67d8

+ 3 - 4
CronAlarm/CronAlarm.csproj

@@ -1,14 +1,13 @@
-<Project Sdk="Microsoft.NET.Sdk.Web">
+<Project Sdk="Microsoft.NET.Sdk.Web">
 
   <PropertyGroup>
-    <TargetFramework>net5.0</TargetFramework>
+    <TargetFramework>net6.0</TargetFramework>
     <UserSecretsId>e0c375bf-fc37-443b-acf2-753c86c89b8b</UserSecretsId>
     <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.9" />
-    <PackageReference Include="Ninject.Web.AspNetCore" Version="5.1.0-alpha1" />
+	  <PackageReference Include="Ninject.Web.AspNetCore" Version="6.1.0-beta1" />
   </ItemGroup>
 
 </Project>

+ 2 - 0
CronAlarm/Pages/_Host.cshtml

@@ -1,4 +1,5 @@
 @page "/"
+@using Microsoft.AspNetCore.Components.Web
 @namespace CronAlarm.Pages
 @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
 @{
@@ -15,6 +16,7 @@
     <link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
     <link href="css/site.css" rel="stylesheet" />
     <link href="CronAlarm.styles.css" rel="stylesheet" />
+    <component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
 </head>
 <body>
     <component type="typeof(App)" render-mode="ServerPrerendered" />

+ 32 - 21
CronAlarm/Program.cs

@@ -1,10 +1,11 @@
 using CronAlarm.Config;
+using Microsoft.AspNetCore.Builder;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
 using Ninject;
 using Ninject.Web.AspNetCore;
-using Ninject.Web.AspNetCore.Hosting;
-using Ninject.Web.Common.SelfHost;
 
 namespace CronAlarm
 {
@@ -12,28 +13,38 @@ namespace CronAlarm
     {
         public static void Main(string[] args)
         {
-            var hostConfiguration = new AspNetCoreHostConfiguration(args)
-                    .UseWebHostBuilder(() => CreateWebHostBuilder(args))
-                    .UseStartup<Startup>()
-                    .UseKestrel()
-                    .BlockOnStart();
+            var kernel = CreateKernel();
+            var builder = WebApplication.CreateBuilder(args);
 
-            var host = new NinjectSelfHostBootstrapper(CreateKernel, hostConfiguration);
-            host.Start();
-        }
+            builder.Host.UseServiceProviderFactory(new NinjectServiceProviderFactory(kernel));
 
-        private static IWebHostBuilder CreateWebHostBuilder(string[] args)
-        {
-            var config = new DefaultWebHostConfiguration(args);
+            // Add services to the container.
+            builder.Services.AddRazorPages();
+            builder.Services.AddServerSideBlazor();
+            builder.Host.ConfigureAppConfiguration((hostingContext, config) =>
+            {
+                config.AddJsonFile("wwwroot/data/settings.json", optional: true, reloadOnChange: true);
+            });
+
+            var app = builder.Build();
 
-            config.ConfigureAll();
-            return config.GetBuilder().ConfigureAppConfiguration((hostingContext, config) =>
-                {
-                    config.AddJsonFile("wwwroot/data/settings.json", optional: true, reloadOnChange: true);
-                });
+            // Configure the HTTP request pipeline.
+            if (!app.Environment.IsDevelopment())
+            {
+                app.UseExceptionHandler("/Error");
+            }
+
+            app.UseStaticFiles();
+
+            app.UseRouting();
+
+            app.MapBlazorHub();
+            app.MapFallbackToPage("/_Host");
+
+            app.Run();
         }
 
-        private static IKernel CreateKernel()
+        private static AspNetCoreKernel CreateKernel()
         {
             var settings = new NinjectSettings();
             // Unfortunately, in .NET Core projects, referenced NuGet assemblies are not copied to the output directory
@@ -42,8 +53,8 @@ namespace CronAlarm
             settings.LoadExtensions = false;
 
             var kernel = new AspNetCoreKernel(settings);
-
-            kernel.Load(typeof(AspNetCoreHostConfiguration).Assembly);
+            kernel.DisableAutomaticSelfBinding();
+            kernel.Load(new AspNetCoreModule());
 
             kernel.Bind<CronApiClient>().ToSelf();
             kernel.Bind<ICronSectionHandler>().To<CronSectionHandler>();

+ 0 - 58
CronAlarm/Startup.cs

@@ -1,58 +0,0 @@
-using Microsoft.AspNetCore.Builder;
-using Microsoft.AspNetCore.Hosting;
-using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Hosting;
-using Ninject.Web.AspNetCore;
-using Ninject.Web.AspNetCore.Hosting;
-
-namespace CronAlarm
-{
-    public class Startup : AspNetCoreStartupBase
-    {
-        public Startup(IConfiguration configuration, IServiceProviderFactory<NinjectServiceProviderBuilder> providerFactory)
-        : base(providerFactory)
-        {
-            Configuration = configuration;
-        }
-
-        public IConfiguration Configuration { get; }
-
-        // 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 override void ConfigureServices(IServiceCollection services)
-        {
-            services.AddRazorPages();
-            services.AddServerSideBlazor();
-        }
-
-        public override void Configure(IApplicationBuilder app)
-        {
-            // For simplicitly, there is only one overload of Configure supported, so in order to get the additional
-            // services, you can just resolve them with the service provider.
-            var env = app.ApplicationServices.GetRequiredService<IWebHostEnvironment>();
-
-            if (env.IsDevelopment())
-            {
-                app.UseDeveloperExceptionPage();
-            }
-            else
-            {
-                app.UseExceptionHandler("/Error");
-                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
-                //app.UseHsts();
-            }
-
-            //app.UseHttpsRedirection();
-            app.UseStaticFiles();
-
-            app.UseRouting();
-
-            app.UseEndpoints(endpoints =>
-            {
-                endpoints.MapBlazorHub();
-                endpoints.MapFallbackToPage("/_Host");
-            });
-        }
-    }
-}

+ 4 - 0
data/settings.json

@@ -45,6 +45,10 @@
           {
             "Label": "09:00 - Lazy",
             "Pattern": "00 09 * * SUN"
+          },
+          {
+            "Label": "08:00 - Early",
+            "Pattern": "00 08 * * SUN"
           }
         ]
       }