PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/code/Stacy/source/Stacy.LoadTests/StacyBenchmarkRunner.cs

https://gitlab.com/ITX8540/stacy
C# | 65 lines | 54 code | 8 blank | 3 comment | 0 complexity | 2bc288e996a24b6543a5da8adeccecd2 MD5 | raw file
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Reflection;
  4. using BenchmarkDotNet.Running;
  5. using MediatR;
  6. using SimpleInjector;
  7. using SimpleInjector.Integration.WebApi;
  8. using Stacy.Domain.Commands;
  9. using Stacy.Infrastructure.Handlers.Requests;
  10. using Stacy.LoadTests.Benchmarks;
  11. using Stacy.Webhooks.Infrastructure;
  12. namespace Stacy.LoadTests
  13. {
  14. public class StacyBenchmarkRunner
  15. {
  16. // TODO: Find a way to DI into BenchmarkRunner.Run.
  17. public static Container GlobalContainer { get; private set; }
  18. static StacyBenchmarkRunner()
  19. {
  20. Configure();
  21. }
  22. public void Run()
  23. {
  24. var benchmarks = new[]
  25. {
  26. //typeof(HelloWorldBenchmark),
  27. typeof(FbWebhookControllerBenchmark),
  28. //typeof(ApiAiWebhookControllerBenchmark)
  29. };
  30. foreach (var benchmark in benchmarks)
  31. {
  32. var summary = BenchmarkRunner.Run(benchmark);
  33. }
  34. }
  35. private static void Configure()
  36. {
  37. var container = new Container();
  38. container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle();
  39. var assemblies = GetAssemblies().ToArray();
  40. container.RegisterSingleton<IMediator, Mediator>();
  41. container.Register(typeof(IRequestHandler<,>), assemblies);
  42. container.Register(typeof(IAsyncRequestHandler<,>), assemblies);
  43. container.RegisterCollection(typeof(INotificationHandler<>), assemblies);
  44. container.RegisterCollection(typeof(INotificationHandler<>), assemblies);
  45. container.RegisterSingleton(new SingleInstanceFactory(container.GetInstance));
  46. container.RegisterSingleton(new MultiInstanceFactory(container.GetAllInstances));
  47. container.RegisterSingleton<IMemoryCacher, MemoryCacher>();
  48. GlobalContainer = container;
  49. }
  50. private static IEnumerable<Assembly> GetAssemblies()
  51. {
  52. yield return typeof(IMediator).GetTypeInfo().Assembly;
  53. yield return typeof(GetGoogleMapsLinkMessage).GetTypeInfo().Assembly;
  54. yield return typeof(GoogleMapsRequestHandler).GetTypeInfo().Assembly;
  55. }
  56. }
  57. }