瀏覽代碼

Add conosole app sample

master
Savorboard 4 年之前
父節點
當前提交
f6588441fc
共有 6 個文件被更改,包括 78 次插入5 次删除
  1. +7
    -0
      CAP.sln
  2. +14
    -0
      samples/Sample.ConsoleApp/EventSubscriber.cs
  3. +37
    -0
      samples/Sample.ConsoleApp/Program.cs
  4. +18
    -0
      samples/Sample.ConsoleApp/Sample.ConsoleApp.csproj
  5. +1
    -5
      samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs
  6. +1
    -0
      src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs

+ 7
- 0
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}


+ 14
- 0
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);
}
}
}

+ 37
- 0
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<EventSubscriber>();

var sp = container.BuildServiceProvider();

sp.GetService<IBootstrapper>().BootstrapAsync(default);

Console.ReadLine();
}
}
}

+ 18
- 0
samples/Sample.ConsoleApp/Sample.ConsoleApp.csproj 查看文件

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\DotNetCore.CAP.RabbitMQ\DotNetCore.CAP.RabbitMQ.csproj" />
<ProjectReference Include="..\..\src\DotNetCore.CAP.MySql\DotNetCore.CAP.MySql.csproj" />
<ProjectReference Include="..\..\src\DotNetCore.CAP\DotNetCore.CAP.csproj" />
</ItemGroup>

</Project>

+ 1
- 5
samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs 查看文件

@@ -21,11 +21,7 @@ namespace Sample.RabbitMQ.MySql.Controllers
[Route("~/without/transaction")]
public async Task<IActionResult> WithoutTransaction()
{
await _capBus.PublishAsync("sample.rabbitmq.mysql", new Person()
{
Id = 123,
Name = "Bar"
});
await _capBus.PublishAsync("sample.rabbitmq.mysql", DateTime.Now);

return Ok();
}


+ 1
- 0
src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs 查看文件

@@ -72,6 +72,7 @@ namespace Microsoft.Extensions.DependencyInjection
services.Configure(setupAction);

//Startup and Hosted
services.AddSingleton<IBootstrapper, Bootstrapper>();
services.AddHostedService<Bootstrapper>();

return new CapBuilder(services);


Loading…
取消
儲存