Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddMemoryCache();

            var config     = JsonConvert.DeserializeObject <AppConfiguration>(File.ReadAllText("config.json"));
            var httpClient = new HttpClient {
                Timeout = TimeSpan.FromSeconds(15D)
            };
            var serviceDiscoveryClient = new ServiceDiscoveryClient(config, httpClient);

            serviceDiscoveryClient.GetServices().GetAwaiter();
            services.AddSingleton <IBlobStorageConfiguration>(config);
            services.AddSingleton <IClientConfiguration>(config);
            services.AddSingleton(serviceDiscoveryClient);
            services.AddSingleton <ServiceDiscoveryService>();
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <Service> > GetServices()
        {
            var cloudBlockBlobs = await serviceDiscoveryClient.GetServices();

            var services = new List <Service>();

            foreach (var blob in cloudBlockBlobs)
            {
                if (!memoryCache.TryGetValue(blob.Name, out Service service))
                {
                    service = await GetService(blob);

                    memoryCache.Set(blob.Name, service);
                }

                services.Add(service);
            }

            return(services);
        }