瀏覽代碼

DotNet Core 5 update

master
30117125 3 年之前
父節點
當前提交
d6f601b5be

+ 4
- 7
UnivateProperties_API/Context/DataContext.cs 查看文件

1
 using Microsoft.EntityFrameworkCore;
1
 using Microsoft.EntityFrameworkCore;
2
-using System.Data.SqlClient;
2
+using Microsoft.Data.SqlClient;
3
 using System.Linq;
3
 using System.Linq;
4
 using UnivateProperties_API.Model;
4
 using UnivateProperties_API.Model;
5
 using UnivateProperties_API.Model.Banks;
5
 using UnivateProperties_API.Model.Banks;
13
 using UnivateProperties_API.Model.Region;
13
 using UnivateProperties_API.Model.Region;
14
 using UnivateProperties_API.Model.Timeshare;
14
 using UnivateProperties_API.Model.Timeshare;
15
 using UnivateProperties_API.Model.Users;
15
 using UnivateProperties_API.Model.Users;
16
+using Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal;
16
 
17
 
17
 namespace UnivateProperties_API.Context
18
 namespace UnivateProperties_API.Context
18
 {
19
 {
23
         {
24
         {
24
             foreach (var extention in options.Extensions)
25
             foreach (var extention in options.Extensions)
25
             {
26
             {
26
-                if (extention.GetType().ToString() == "Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal.NpgsqlOptionsExtension")
27
+                if (extention.GetType().ToString() == "Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal.SqlServerOptionsExtension")
27
                 {
28
                 {
28
-                    connectionString = ((Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal.NpgsqlOptionsExtension)extention).ConnectionString;
29
-                }
30
-                else if (extention.GetType().ToString() == "Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal.SqlServerOptionsExtension")
31
-                {
32
-                    connectionString = ((Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal.SqlServerOptionsExtension)extention).ConnectionString;
29
+                    connectionString = ((SqlServerOptionsExtension)extention).ConnectionString;
33
                 }
30
                 }
34
             }
31
             }
35
         }
32
         }

+ 8
- 11
UnivateProperties_API/Startup.cs 查看文件

1
 using AutoMapper;
1
 using AutoMapper;
2
 using Microsoft.AspNetCore.Authentication.JwtBearer;
2
 using Microsoft.AspNetCore.Authentication.JwtBearer;
3
 using Microsoft.AspNetCore.Builder;
3
 using Microsoft.AspNetCore.Builder;
4
-using Microsoft.AspNetCore.Cors.Infrastructure;
5
 using Microsoft.AspNetCore.Hosting;
4
 using Microsoft.AspNetCore.Hosting;
6
 using Microsoft.AspNetCore.Mvc;
5
 using Microsoft.AspNetCore.Mvc;
7
-using Microsoft.AspNetCore.Mvc.Cors.Internal;
8
 using Microsoft.EntityFrameworkCore;
6
 using Microsoft.EntityFrameworkCore;
9
 using Microsoft.Extensions.Configuration;
7
 using Microsoft.Extensions.Configuration;
10
 using Microsoft.Extensions.DependencyInjection;
8
 using Microsoft.Extensions.DependencyInjection;
14
 using UnivateProperties_API.Context;
12
 using UnivateProperties_API.Context;
15
 using UnivateProperties_API.Helpers;
13
 using UnivateProperties_API.Helpers;
16
 using UnivateProperties_API.Model.Banks;
14
 using UnivateProperties_API.Model.Banks;
17
-using UnivateProperties_API.Model.Campaigns;
18
 using UnivateProperties_API.Model.Communication;
15
 using UnivateProperties_API.Model.Communication;
19
 using UnivateProperties_API.Model.Financial;
16
 using UnivateProperties_API.Model.Financial;
20
 using UnivateProperties_API.Model.Misc;
17
 using UnivateProperties_API.Model.Misc;
21
-using UnivateProperties_API.Model.ProcessFlow;
22
 using UnivateProperties_API.Model.Properties;
18
 using UnivateProperties_API.Model.Properties;
23
 using UnivateProperties_API.Model.Region;
19
 using UnivateProperties_API.Model.Region;
24
 using UnivateProperties_API.Model.Timeshare;
20
 using UnivateProperties_API.Model.Timeshare;
50
         public void ConfigureServices(IServiceCollection services)
46
         public void ConfigureServices(IServiceCollection services)
51
         {            
47
         {            
52
             services.AddAutoMapper();
48
             services.AddAutoMapper();
49
+            services.AddHealthChecks();
50
+            services.AddControllers();
53
             services.AddCors(o => o.AddPolicy("MyPolicy", builder =>
51
             services.AddCors(o => o.AddPolicy("MyPolicy", builder =>
54
             {
52
             {
55
                 builder.AllowAnyOrigin()                        
53
                 builder.AllowAnyOrigin()                        
56
                        .AllowAnyMethod()
54
                        .AllowAnyMethod()
57
                        .AllowAnyHeader();                       
55
                        .AllowAnyHeader();                       
58
-            }));            
59
-            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
56
+            }));
60
             services.AddDbContext<DataContext>(o => o.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
57
             services.AddDbContext<DataContext>(o => o.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
61
             MyCommon.TenderUrl = Configuration.GetConnectionString("TenderConnection");
58
             MyCommon.TenderUrl = Configuration.GetConnectionString("TenderConnection");
62
             MyCommon.Reservations = Configuration.GetConnectionString("ReservationsURL");
59
             MyCommon.Reservations = Configuration.GetConnectionString("ReservationsURL");
174
             #region Campaign 
171
             #region Campaign 
175
             services.AddTransient<ICampaignRepository, CampaignRepository>();
172
             services.AddTransient<ICampaignRepository, CampaignRepository>();
176
             #endregion
173
             #endregion
177
-            services.Configure<MvcOptions>(options =>
178
-            {
179
-                options.Filters.Add(new CorsAuthorizationFilterFactory("MyPolicy"));                
180
-            });
181
         }
174
         }
182
 
175
 
183
         public void Configure(IApplicationBuilder app, IHostingEnvironment env)
176
         public void Configure(IApplicationBuilder app, IHostingEnvironment env)
187
             //{
180
             //{
188
             app.UseDeveloperExceptionPage();
181
             app.UseDeveloperExceptionPage();
189
             //}
182
             //}
183
+            app.UseRouting();
190
             app.UseCors(x => x                
184
             app.UseCors(x => x                
191
                 .AllowAnyOrigin()
185
                 .AllowAnyOrigin()
192
                 .AllowAnyMethod()
186
                 .AllowAnyMethod()
193
                 .AllowAnyHeader());                
187
                 .AllowAnyHeader());                
194
             app.UseAuthentication();
188
             app.UseAuthentication();
195
             app.UseHttpsRedirection();
189
             app.UseHttpsRedirection();
196
-            app.UseMvc();
190
+            app.UseEndpoints(endpoints =>
191
+            {
192
+                endpoints.MapControllers(); //Routes for my API controllers
193
+            });
197
         }
194
         }
198
 
195
 
199
         private static void UpdateDatabase(IApplicationBuilder app)
196
         private static void UpdateDatabase(IApplicationBuilder app)

+ 10
- 6
UnivateProperties_API/UnivateProperties_API.csproj 查看文件

1
 <Project Sdk="Microsoft.NET.Sdk.Web">
1
 <Project Sdk="Microsoft.NET.Sdk.Web">
2
 
2
 
3
   <PropertyGroup>
3
   <PropertyGroup>
4
-    <TargetFramework>netcoreapp2.2</TargetFramework>
5
-    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
4
+    <TargetFramework>netcoreapp5.0</TargetFramework>
5
+    <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
6
     <TargetLatestRuntimePatch>false</TargetLatestRuntimePatch>
6
     <TargetLatestRuntimePatch>false</TargetLatestRuntimePatch>
7
+    <UserSecretsId>af6d5f9c-a077-4393-8907-888822f3e809</UserSecretsId>
7
   </PropertyGroup>
8
   </PropertyGroup>
8
 
9
 
9
   <ItemGroup>
10
   <ItemGroup>
17
     <PackageReference Include="MailKit" Version="2.8.0" />
18
     <PackageReference Include="MailKit" Version="2.8.0" />
18
     <PackageReference Include="Microsoft.AspNet.WebApi.Cors" Version="5.2.7" />
19
     <PackageReference Include="Microsoft.AspNet.WebApi.Cors" Version="5.2.7" />
19
     <PackageReference Include="Microsoft.AspNetCore.App" />
20
     <PackageReference Include="Microsoft.AspNetCore.App" />
21
+    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.0.3" />
20
     <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
22
     <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
21
-    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" />
23
+    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.5" />
24
+    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.5" />
25
+    <PackageReference Include="Microsoft.Extensions.Caching.SqlServer" Version="5.0.1" />
26
+    <PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
22
     <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.4" />
27
     <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.4" />
23
     <PackageReference Include="MimeKit" Version="2.9.1" />
28
     <PackageReference Include="MimeKit" Version="2.9.1" />
24
-    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.2.0" />
25
     <PackageReference Include="RestSharp" Version="106.11.4" />
29
     <PackageReference Include="RestSharp" Version="106.11.4" />
26
-    <PackageReference Include="System.Drawing.Common" Version="4.6.0" />
30
+    <PackageReference Include="System.Drawing.Common" Version="5.0.2" />
27
   </ItemGroup>
31
   </ItemGroup>
28
 
32
 
29
-</Project>
33
+</Project>

Loading…
取消
儲存