2020-07-03 13:51:41 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using ExampleLib;
|
|
|
|
|
using Messaging.TapetiExample;
|
|
|
|
|
using SimpleInjector;
|
|
|
|
|
using Tapeti;
|
|
|
|
|
using Tapeti.DataAnnotations;
|
|
|
|
|
using Tapeti.Default;
|
|
|
|
|
using Tapeti.SimpleInjector;
|
|
|
|
|
|
|
|
|
|
namespace _06_StatelessRequestResponse
|
|
|
|
|
{
|
|
|
|
|
public class Program
|
|
|
|
|
{
|
2022-02-09 08:19:56 +00:00
|
|
|
|
public static void Main()
|
2020-07-03 13:51:41 +00:00
|
|
|
|
{
|
|
|
|
|
var container = new Container();
|
|
|
|
|
var dependencyResolver = new SimpleInjectorDependencyResolver(container);
|
|
|
|
|
|
|
|
|
|
container.Register<ILogger, ConsoleLogger>();
|
|
|
|
|
|
|
|
|
|
var helper = new ExampleConsoleApp(dependencyResolver);
|
|
|
|
|
helper.Run(MainAsync);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal static async Task MainAsync(IDependencyResolver dependencyResolver, Func<Task> waitForDone)
|
|
|
|
|
{
|
|
|
|
|
var config = new TapetiConfig(dependencyResolver)
|
|
|
|
|
.WithDataAnnotations()
|
|
|
|
|
.RegisterAllControllers()
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
|
2022-02-09 08:19:56 +00:00
|
|
|
|
await using var connection = new TapetiConnection(config);
|
|
|
|
|
await connection.Subscribe();
|
2020-07-03 13:51:41 +00:00
|
|
|
|
|
2022-02-09 08:19:56 +00:00
|
|
|
|
var publisher = dependencyResolver.Resolve<IPublisher>();
|
|
|
|
|
await publisher.PublishRequest<ExampleMessageController, QuoteRequestMessage, QuoteResponseMessage>(
|
|
|
|
|
new QuoteRequestMessage
|
|
|
|
|
{
|
|
|
|
|
Amount = 1
|
|
|
|
|
},
|
|
|
|
|
c => c.HandleQuoteResponse);
|
2020-07-03 13:51:41 +00:00
|
|
|
|
|
2022-02-09 08:19:56 +00:00
|
|
|
|
await waitForDone();
|
2020-07-03 13:51:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|