From 673bd335d4c22e939a5947bba1e818a8bfcb301f Mon Sep 17 00:00:00 2001 From: Savorboard Date: Thu, 24 Oct 2019 12:03:35 +0800 Subject: [PATCH] upgrade to netcoreapp3.0 --- samples/Sample.RabbitMQ.MySql/AppDbContext.cs | 15 +++++++++++++++ .../Controllers/ValuesController.cs | 11 ++++++++--- samples/Sample.RabbitMQ.MySql/Program.cs | 17 +++++++++-------- .../Properties/launchSettings.json | 15 ++++++++------- .../Sample.RabbitMQ.MySql.csproj | 7 +++---- samples/Sample.RabbitMQ.MySql/Startup.cs | 12 +++++++----- 6 files changed, 50 insertions(+), 27 deletions(-) diff --git a/samples/Sample.RabbitMQ.MySql/AppDbContext.cs b/samples/Sample.RabbitMQ.MySql/AppDbContext.cs index 346209e..e5b22e5 100644 --- a/samples/Sample.RabbitMQ.MySql/AppDbContext.cs +++ b/samples/Sample.RabbitMQ.MySql/AppDbContext.cs @@ -7,8 +7,23 @@ namespace Sample.RabbitMQ.MySql public int Id { get; set; } public string Name { get; set; } + + public override string ToString() + { + return $"Name:{Name}, Id:{Id}"; + } } + public class Person2 + { + public int Id { get; set; } + public string Name { get; set; } + + public override string ToString() + { + return $"Name:{Name}, Id:{Id}"; + } + } public class AppDbContext : DbContext { public const string ConnectionString = "Server=192.168.2.120;Database=captest;UserId=root;Password=123123;"; diff --git a/samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs b/samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs index 4e7bfb3..b8c920f 100644 --- a/samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs +++ b/samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Data; using System.Threading.Tasks; using Dapper; @@ -21,7 +22,11 @@ namespace Sample.RabbitMQ.MySql.Controllers [Route("~/without/transaction")] public async Task WithoutTransaction() { - await _capBus.PublishAsync("sample.rabbitmq.mysql", DateTime.Now); + await _capBus.PublishAsync("sample.rabbitmq.mysql", new Person() + { + Id = 123, + Name = "Bar" + }); return Ok(); } @@ -69,9 +74,9 @@ namespace Sample.RabbitMQ.MySql.Controllers [NonAction] [CapSubscribe("sample.rabbitmq.mysql")] - public void Subscriber(DateTime time) + public void Subscriber(Person2 p) { - Console.WriteLine($@"{DateTime.Now}, Subscriber invoked, Sent time:{time}"); + Console.WriteLine($@"{DateTime.Now} Subscriber invoked, Info: {p}"); } } } diff --git a/samples/Sample.RabbitMQ.MySql/Program.cs b/samples/Sample.RabbitMQ.MySql/Program.cs index 80d0fe6..07a0ced 100644 --- a/samples/Sample.RabbitMQ.MySql/Program.cs +++ b/samples/Sample.RabbitMQ.MySql/Program.cs @@ -1,5 +1,5 @@ -using Microsoft.AspNetCore; -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; namespace Sample.RabbitMQ.MySql { @@ -7,13 +7,14 @@ namespace Sample.RabbitMQ.MySql { public static void Main(string[] args) { - BuildWebHost(args).Run(); + CreateHostBuilder(args).Build().Run(); } - public static IWebHost BuildWebHost(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup() - .UseUrls("http://*:15173") - .Build(); + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); } } diff --git a/samples/Sample.RabbitMQ.MySql/Properties/launchSettings.json b/samples/Sample.RabbitMQ.MySql/Properties/launchSettings.json index c0a90d4..0898ae3 100644 --- a/samples/Sample.RabbitMQ.MySql/Properties/launchSettings.json +++ b/samples/Sample.RabbitMQ.MySql/Properties/launchSettings.json @@ -1,10 +1,11 @@ -{ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:57171/", - "sslPort": 0 + "applicationUrl": "http://localhost:49558", + "sslPort": 44332 } }, "profiles": { @@ -20,10 +21,10 @@ "commandName": "Project", "launchBrowser": true, "launchUrl": "cap", + "applicationUrl": "http://localhost:5000", "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Production" - }, - "applicationUrl": "http://localhost:57173/" + "ASPNETCORE_ENVIRONMENT": "Development" + } } } -} \ No newline at end of file +} diff --git a/samples/Sample.RabbitMQ.MySql/Sample.RabbitMQ.MySql.csproj b/samples/Sample.RabbitMQ.MySql/Sample.RabbitMQ.MySql.csproj index 5e3b6b5..8756e56 100644 --- a/samples/Sample.RabbitMQ.MySql/Sample.RabbitMQ.MySql.csproj +++ b/samples/Sample.RabbitMQ.MySql/Sample.RabbitMQ.MySql.csproj @@ -1,13 +1,12 @@  - netcoreapp2.2 + netcoreapp3.0 - - - + + diff --git a/samples/Sample.RabbitMQ.MySql/Startup.cs b/samples/Sample.RabbitMQ.MySql/Startup.cs index f402deb..f29e53f 100644 --- a/samples/Sample.RabbitMQ.MySql/Startup.cs +++ b/samples/Sample.RabbitMQ.MySql/Startup.cs @@ -1,9 +1,7 @@ using System; using DotNetCore.CAP.Messages; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; namespace Sample.RabbitMQ.MySql { @@ -26,12 +24,16 @@ namespace Sample.RabbitMQ.MySql }; }); - services.AddMvc(); + services.AddControllers(); } - public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) + public void Configure(IApplicationBuilder app) { - app.UseMvc(); + app.UseRouting(); + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); } } }