Sfoglia il codice sorgente

DotNet Core 5 update

master
30117125 3 anni fa
parent
commit
d6f601b5be

+ 4
- 7
UnivateProperties_API/Context/DataContext.cs Vedi File

@@ -1,5 +1,5 @@
1 1
 using Microsoft.EntityFrameworkCore;
2
-using System.Data.SqlClient;
2
+using Microsoft.Data.SqlClient;
3 3
 using System.Linq;
4 4
 using UnivateProperties_API.Model;
5 5
 using UnivateProperties_API.Model.Banks;
@@ -13,6 +13,7 @@ using UnivateProperties_API.Model.Properties;
13 13
 using UnivateProperties_API.Model.Region;
14 14
 using UnivateProperties_API.Model.Timeshare;
15 15
 using UnivateProperties_API.Model.Users;
16
+using Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal;
16 17
 
17 18
 namespace UnivateProperties_API.Context
18 19
 {
@@ -23,13 +24,9 @@ namespace UnivateProperties_API.Context
23 24
         {
24 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 Vedi File

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

+ 10
- 6
UnivateProperties_API/UnivateProperties_API.csproj Vedi File

@@ -1,9 +1,10 @@
1 1
 <Project Sdk="Microsoft.NET.Sdk.Web">
2 2
 
3 3
   <PropertyGroup>
4
-    <TargetFramework>netcoreapp2.2</TargetFramework>
5
-    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
4
+    <TargetFramework>netcoreapp5.0</TargetFramework>
5
+    <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
6 6
     <TargetLatestRuntimePatch>false</TargetLatestRuntimePatch>
7
+    <UserSecretsId>af6d5f9c-a077-4393-8907-888822f3e809</UserSecretsId>
7 8
   </PropertyGroup>
8 9
 
9 10
   <ItemGroup>
@@ -17,13 +18,16 @@
17 18
     <PackageReference Include="MailKit" Version="2.8.0" />
18 19
     <PackageReference Include="Microsoft.AspNet.WebApi.Cors" Version="5.2.7" />
19 20
     <PackageReference Include="Microsoft.AspNetCore.App" />
21
+    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.0.3" />
20 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 27
     <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.4" />
23 28
     <PackageReference Include="MimeKit" Version="2.9.1" />
24
-    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.2.0" />
25 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 31
   </ItemGroup>
28 32
 
29
-</Project>
33
+</Project>

Loading…
Annulla
Salva