mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	plying around with service providers
This commit is contained in:
		@@ -7,6 +7,7 @@ using Ocelot.Configuration.File;
 | 
			
		||||
using Ocelot.Configuration.Parser;
 | 
			
		||||
using Ocelot.Configuration.Validator;
 | 
			
		||||
using Ocelot.Responses;
 | 
			
		||||
using Ocelot.ServiceDiscovery;
 | 
			
		||||
using Ocelot.Utilities;
 | 
			
		||||
using Ocelot.Values;
 | 
			
		||||
 | 
			
		||||
@@ -104,7 +105,22 @@ namespace Ocelot.Configuration.Creator
 | 
			
		||||
 | 
			
		||||
            //ideal world we would get the host and port, then make the request using it, then release the connection to the lb
 | 
			
		||||
 | 
			
		||||
            Func<HostAndPort> downstreamHostAndPortFunc = () => new HostAndPort(reRoute.DownstreamHost.Trim('/'), reRoute.DownstreamPort);
 | 
			
		||||
            Func<HostAndPort> downstreamHostAndPortFunc = () => {
 | 
			
		||||
 | 
			
		||||
                //service provider factory takes the reRoute
 | 
			
		||||
                    //can return no service provider (just use ocelot config)
 | 
			
		||||
                    //can return consol service provider
 | 
			
		||||
                //returns a service provider
 | 
			
		||||
                //we call get on the service provider
 | 
			
		||||
                    //could reutrn services from consol or just configuration.json
 | 
			
		||||
                //this returns a list of services and we take the first one
 | 
			
		||||
                var hostAndPort = new HostAndPort(reRoute.DownstreamHost.Trim('/'), reRoute.DownstreamPort);
 | 
			
		||||
                var services = new List<Service>();
 | 
			
		||||
                var serviceProvider = new NoServiceProvider(services);
 | 
			
		||||
                var service = serviceProvider.Get();
 | 
			
		||||
                var firstHostAndPort = service[0].HostAndPort;
 | 
			
		||||
                return firstHostAndPort;
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            if (isAuthenticated)
 | 
			
		||||
            {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										10
									
								
								src/Ocelot/ServiceDiscovery/IServiceProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								src/Ocelot/ServiceDiscovery/IServiceProvider.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using Ocelot.Values;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.ServiceDiscovery
 | 
			
		||||
{
 | 
			
		||||
    public interface IServiceProvider
 | 
			
		||||
    {
 | 
			
		||||
         List<Service> Get();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										9
									
								
								src/Ocelot/ServiceDiscovery/IServiceProviderFactory.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								src/Ocelot/ServiceDiscovery/IServiceProviderFactory.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
using Ocelot.Configuration;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.ServiceDiscovery
 | 
			
		||||
{
 | 
			
		||||
    public interface IServiceProviderFactory
 | 
			
		||||
    {
 | 
			
		||||
        Ocelot.ServiceDiscovery.IServiceProvider Get(ReRoute reRoute);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										20
									
								
								src/Ocelot/ServiceDiscovery/NoServiceProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								src/Ocelot/ServiceDiscovery/NoServiceProvider.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using Ocelot.Values;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.ServiceDiscovery
 | 
			
		||||
{
 | 
			
		||||
    public class NoServiceProvider : IServiceProvider
 | 
			
		||||
    {
 | 
			
		||||
        private List<Service> _services;
 | 
			
		||||
 | 
			
		||||
        public NoServiceProvider(List<Service> services)
 | 
			
		||||
        {
 | 
			
		||||
            _services = services;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public List<Service> Get()
 | 
			
		||||
        {
 | 
			
		||||
            return _services;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										13
									
								
								src/Ocelot/ServiceDiscovery/ServiceProviderFactory.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/Ocelot/ServiceDiscovery/ServiceProviderFactory.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
			
		||||
using System;
 | 
			
		||||
using Ocelot.Configuration;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.ServiceDiscovery
 | 
			
		||||
{
 | 
			
		||||
    public class ServiceProviderFactory : IServiceProviderFactory
 | 
			
		||||
    {
 | 
			
		||||
        public  Ocelot.ServiceDiscovery.IServiceProvider Get(ReRoute reRoute)
 | 
			
		||||
        {
 | 
			
		||||
            throw new NotImplementedException();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										13
									
								
								src/Ocelot/Values/Service.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/Ocelot/Values/Service.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
			
		||||
namespace Ocelot.Values
 | 
			
		||||
{
 | 
			
		||||
    public class Service
 | 
			
		||||
    {
 | 
			
		||||
        public Service(string name, HostAndPort hostAndPort)
 | 
			
		||||
        {
 | 
			
		||||
            Name = name;
 | 
			
		||||
            HostAndPort = hostAndPort;
 | 
			
		||||
        }
 | 
			
		||||
        public string Name {get; private set;}
 | 
			
		||||
        public HostAndPort HostAndPort {get; private set;}
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user