From f6588441fc148fb15d62f8ff5a58207d2398ac12 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Wed, 13 May 2020 14:17:25 +0800 Subject: [PATCH] Add conosole app sample --- CAP.sln | 7 ++++ samples/Sample.ConsoleApp/EventSubscriber.cs | 14 +++++++ samples/Sample.ConsoleApp/Program.cs | 37 +++++++++++++++++++ .../Sample.ConsoleApp.csproj | 18 +++++++++ .../Controllers/ValuesController.cs | 6 +-- .../CAP.ServiceCollectionExtensions.cs | 1 + 6 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 samples/Sample.ConsoleApp/EventSubscriber.cs create mode 100644 samples/Sample.ConsoleApp/Program.cs create mode 100644 samples/Sample.ConsoleApp/Sample.ConsoleApp.csproj diff --git a/CAP.sln b/CAP.sln index d2c4723..b5be9a6 100644 --- a/CAP.sln +++ b/CAP.sln @@ -63,6 +63,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetCore.CAP.InMemoryStor EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetCore.CAP.Test", "test\DotNetCore.CAP.Test\DotNetCore.CAP.Test.csproj", "{75CC45E6-BF06-40F4-977D-10DCC05B2EFA}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.ConsoleApp", "samples\Sample.ConsoleApp\Sample.ConsoleApp.csproj", "{2B0F467E-ABBD-4A51-BF38-D4F609DB6266}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -141,6 +143,10 @@ Global {75CC45E6-BF06-40F4-977D-10DCC05B2EFA}.Debug|Any CPU.Build.0 = Debug|Any CPU {75CC45E6-BF06-40F4-977D-10DCC05B2EFA}.Release|Any CPU.ActiveCfg = Release|Any CPU {75CC45E6-BF06-40F4-977D-10DCC05B2EFA}.Release|Any CPU.Build.0 = Release|Any CPU + {2B0F467E-ABBD-4A51-BF38-D4F609DB6266}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2B0F467E-ABBD-4A51-BF38-D4F609DB6266}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2B0F467E-ABBD-4A51-BF38-D4F609DB6266}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2B0F467E-ABBD-4A51-BF38-D4F609DB6266}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -164,6 +170,7 @@ Global {F8EF381A-FE83-40B3-A63D-09D83851B0FB} = {10C0818D-9160-4B80-BB86-DDE925B64D43} {93176BAE-914B-4BED-9DE3-01FFB4F27FC5} = {9B2AE124-6636-4DE9-83A3-70360DABD0C4} {75CC45E6-BF06-40F4-977D-10DCC05B2EFA} = {C09CDAB0-6DD4-46E9-B7F3-3EF2A4741EA0} + {2B0F467E-ABBD-4A51-BF38-D4F609DB6266} = {3A6B6931-A123-477A-9469-8B468B5385AF} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {2E70565D-94CF-40B4-BFE1-AC18D5F736AB} diff --git a/samples/Sample.ConsoleApp/EventSubscriber.cs b/samples/Sample.ConsoleApp/EventSubscriber.cs new file mode 100644 index 0000000..d09a7a8 --- /dev/null +++ b/samples/Sample.ConsoleApp/EventSubscriber.cs @@ -0,0 +1,14 @@ +using System; +using DotNetCore.CAP; + +namespace Sample.ConsoleApp +{ + public class EventSubscriber : ICapSubscribe + { + [CapSubscribe("sample.console.showtime")] + public void ShowTime(DateTime date) + { + Console.WriteLine(date); + } + } +} diff --git a/samples/Sample.ConsoleApp/Program.cs b/samples/Sample.ConsoleApp/Program.cs new file mode 100644 index 0000000..f0315e1 --- /dev/null +++ b/samples/Sample.ConsoleApp/Program.cs @@ -0,0 +1,37 @@ +using System; +using DotNetCore.CAP.Internal; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace Sample.ConsoleApp +{ + public class Program + { + public static void Main(string[] args) + { + var container = new ServiceCollection(); + + container.AddLogging(x => x.AddConsole()); + container.AddCap(x => + { + //console app does not support dashboard + + x.UseMySql("Server=192.168.3.57;Port=3307;Database=captest;Uid=root;Pwd=123123;"); + x.UseRabbitMQ(z => + { + z.HostName = "192.168.3.57"; + z.UserName = "user"; + z.Password = "wJ0p5gSs17"; + }); + }); + + container.AddSingleton(); + + var sp = container.BuildServiceProvider(); + + sp.GetService().BootstrapAsync(default); + + Console.ReadLine(); + } + } +} \ No newline at end of file diff --git a/samples/Sample.ConsoleApp/Sample.ConsoleApp.csproj b/samples/Sample.ConsoleApp/Sample.ConsoleApp.csproj new file mode 100644 index 0000000..05a76ac --- /dev/null +++ b/samples/Sample.ConsoleApp/Sample.ConsoleApp.csproj @@ -0,0 +1,18 @@ + + + + netcoreapp3.1 + Exe + + + + + + + + + + + + + diff --git a/samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs b/samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs index ae934e7..a20fad2 100644 --- a/samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs +++ b/samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs @@ -21,11 +21,7 @@ namespace Sample.RabbitMQ.MySql.Controllers [Route("~/without/transaction")] public async Task WithoutTransaction() { - await _capBus.PublishAsync("sample.rabbitmq.mysql", new Person() - { - Id = 123, - Name = "Bar" - }); + await _capBus.PublishAsync("sample.rabbitmq.mysql", DateTime.Now); return Ok(); } diff --git a/src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs b/src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs index 55d5fbc..ecc703d 100644 --- a/src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs +++ b/src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs @@ -72,6 +72,7 @@ namespace Microsoft.Extensions.DependencyInjection services.Configure(setupAction); //Startup and Hosted + services.AddSingleton(); services.AddHostedService(); return new CapBuilder(services);