2019-08-17 14:19:29 +02: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;
|
|
|
|
|
using Tapeti.Transient;
|
|
|
|
|
|
|
|
|
|
namespace _04_Transient
|
|
|
|
|
{
|
|
|
|
|
public class Program
|
|
|
|
|
{
|
2022-02-09 09:19:56 +01:00
|
|
|
|
public static void Main()
|
2019-08-17 14:19:29 +02: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()
|
|
|
|
|
.WithTransient(TimeSpan.FromSeconds(5), "tapeti.example.04.transient")
|
|
|
|
|
.RegisterAllControllers()
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
|
2022-02-09 09:19:56 +01:00
|
|
|
|
await using var connection = new TapetiConnection(config);
|
|
|
|
|
await connection.Subscribe();
|
2019-08-17 14:19:29 +02:00
|
|
|
|
|
|
|
|
|
|
2022-02-09 09:19:56 +01:00
|
|
|
|
Console.WriteLine("Sending request...");
|
2019-08-17 14:19:29 +02:00
|
|
|
|
|
2022-02-09 09:19:56 +01:00
|
|
|
|
var transientPublisher = dependencyResolver.Resolve<ITransientPublisher>();
|
|
|
|
|
var response = await transientPublisher.RequestResponse<LoggedInUsersRequestMessage, LoggedInUsersResponseMessage>(
|
|
|
|
|
new LoggedInUsersRequestMessage());
|
2019-08-17 14:19:29 +02:00
|
|
|
|
|
2022-02-09 09:19:56 +01:00
|
|
|
|
Console.WriteLine("Response: " + response.Count);
|
2019-08-17 14:19:29 +02:00
|
|
|
|
|
|
|
|
|
|
2022-02-09 09:19:56 +01:00
|
|
|
|
// Unlike the other example, there is no need to call waitForDone, once we're here the response has been handled.
|
2019-08-17 14:19:29 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|