Exemplo n.º 1
0
        /// <summary>Discovers the routes.</summary>
        /// <param name="builder">The builder.</param>
        /// <param name="routingTable">The routing table.</param>
        /// <param name="config">The configuration.</param>
        private static void DiscoverRoutes(IApplicationBuilder builder, IApiRoutingTable routingTable, IDeepSleepServiceConfiguration config)
        {
            var discoveryStrategies = config?.DiscoveryStrategies == null || config.DiscoveryStrategies.Count == 0
                ? DiscoveryStrategies.Default()
                : config.DiscoveryStrategies.Where(d => d != null).ToList();

            foreach (var strategy in discoveryStrategies)
            {
                if (strategy == null)
                {
                    continue;
                }

                var task = Task.Run(async() =>
                {
                    using (var scope = builder.ApplicationServices.CreateScope())
                    {
                        return(await strategy.DiscoverRoutes(scope.ServiceProvider).ConfigureAwait(false));
                    }
                });

                var registrations = task.Result;

                foreach (var registration in registrations)
                {
                    if (registration == null)
                    {
                        continue;
                    }

                    routingTable.AddRoute(registration);
                }
            }
        }
Exemplo n.º 2
0
        public void discoverystrategies___default_contains_correct_strategies()
        {
            var strategies = DiscoveryStrategies.Default();

            strategies.Should().NotBeNull();
            strategies.Should().HaveCount(2);
            strategies[0].GetType().Should().Be(typeof(AttributeRouteDiscoveryStrategy));
            strategies[1].GetType().Should().Be(typeof(DelegatedRouteDiscoveryStrategy));
        }