├── Gateway ├── .dockerignore ├── Dockerfile ├── appsettings.Development.json ├── appsettings.json ├── Gateway.csproj ├── Program.cs ├── Properties │ └── launchSettings.json ├── configuration.json ├── tempkey.rsa └── Startup.cs ├── ServiceA ├── .dockerignore ├── Dockerfile ├── appsettings.Development.json ├── appsettings.json ├── Program.cs ├── ServiceA.csproj ├── Properties │ └── launchSettings.json ├── Controllers │ └── ValuesController.cs └── Startup.cs ├── ServiceB ├── .dockerignore ├── Dockerfile ├── appsettings.Development.json ├── appsettings.json ├── Program.cs ├── ServiceB.csproj ├── Properties │ └── launchSettings.json ├── Controllers │ └── ValuesController.cs └── Startup.cs ├── docker-compose.ci.build.yml ├── readme.md ├── docker-compose.yml ├── docker-compose.override.yml ├── docker-compose.dcproj ├── Ocelot.sln ├── .gitattributes └── .gitignore /Gateway/.dockerignore: -------------------------------------------------------------------------------- 1 | * 2 | !obj/Docker/publish/* 3 | !obj/Docker/empty/ 4 | -------------------------------------------------------------------------------- /ServiceA/.dockerignore: -------------------------------------------------------------------------------- 1 | * 2 | !obj/Docker/publish/* 3 | !obj/Docker/empty/ 4 | -------------------------------------------------------------------------------- /ServiceB/.dockerignore: -------------------------------------------------------------------------------- 1 | * 2 | !obj/Docker/publish/* 3 | !obj/Docker/empty/ 4 | -------------------------------------------------------------------------------- /Gateway/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM microsoft/aspnetcore:2.0 2 | ARG source 3 | WORKDIR /app 4 | EXPOSE 80 5 | COPY ${source:-obj/Docker/publish} . 6 | ENTRYPOINT ["dotnet", "Gateway.dll"] 7 | -------------------------------------------------------------------------------- /ServiceA/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM microsoft/aspnetcore:2.0 2 | ARG source 3 | WORKDIR /app 4 | EXPOSE 80 5 | COPY ${source:-obj/Docker/publish} . 6 | ENTRYPOINT ["dotnet", "ServiceA.dll"] 7 | -------------------------------------------------------------------------------- /ServiceB/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM microsoft/aspnetcore:2.0 2 | ARG source 3 | WORKDIR /app 4 | EXPOSE 80 5 | COPY ${source:-obj/Docker/publish} . 6 | ENTRYPOINT ["dotnet", "ServiceB.dll"] 7 | -------------------------------------------------------------------------------- /Gateway/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /ServiceA/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /ServiceB/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Gateway/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "Debug": { 5 | "LogLevel": { 6 | "Default": "Warning" 7 | } 8 | }, 9 | "Console": { 10 | "LogLevel": { 11 | "Default": "Warning" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ServiceA/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "Debug": { 5 | "LogLevel": { 6 | "Default": "Warning" 7 | } 8 | }, 9 | "Console": { 10 | "LogLevel": { 11 | "Default": "Warning" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ServiceB/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "Debug": { 5 | "LogLevel": { 6 | "Default": "Warning" 7 | } 8 | }, 9 | "Console": { 10 | "LogLevel": { 11 | "Default": "Warning" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /docker-compose.ci.build.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | ci-build: 5 | image: microsoft/aspnetcore-build:1.0-2.0 6 | volumes: 7 | - .:/src 8 | working_dir: /src 9 | command: /bin/bash -c "dotnet restore ./Ocelot.sln && dotnet publish ./Ocelot.sln -c Release -o ./obj/Docker/publish" 10 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## Ocelot: Sample Gateway Implementation 2 | 3 | This is a sample implementation of a gateway using Ocelot, .net Core 2.0 and docker. 4 | 5 | To find out more about Ocelot, you can check their official [documentation](http://ocelot.readthedocs.io) and their [repository](https://github.com/TomPallister/Ocelot) 6 | 7 | ### Pre-requisites 8 | 9 | * Visual Studio 2017 15.3+ 10 | * Docker -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | servicea: 5 | image: servicea 6 | build: 7 | context: ./ServiceA 8 | dockerfile: Dockerfile 9 | 10 | serviceb: 11 | image: serviceb 12 | build: 13 | context: ./ServiceB 14 | dockerfile: Dockerfile 15 | 16 | gateway: 17 | image: gateway 18 | build: 19 | context: ./Gateway 20 | dockerfile: Dockerfile 21 | -------------------------------------------------------------------------------- /docker-compose.override.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | servicea: 5 | environment: 6 | - ASPNETCORE_ENVIRONMENT=Development 7 | ports: 8 | - "80" 9 | 10 | serviceb: 11 | environment: 12 | - ASPNETCORE_ENVIRONMENT=Development 13 | ports: 14 | - "80" 15 | 16 | gateway: 17 | environment: 18 | - ASPNETCORE_ENVIRONMENT=Development 19 | ports: 20 | - "80" 21 | -------------------------------------------------------------------------------- /ServiceA/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore; 2 | using Microsoft.AspNetCore.Hosting; 3 | 4 | namespace ServiceA 5 | { 6 | public class Program 7 | { 8 | public static void Main(string[] args) 9 | { 10 | BuildWebHost(args).Run(); 11 | } 12 | 13 | public static IWebHost BuildWebHost(string[] args) => 14 | WebHost.CreateDefaultBuilder(args) 15 | .UseStartup() 16 | .Build(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ServiceB/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore; 2 | using Microsoft.AspNetCore.Hosting; 3 | 4 | namespace ServiceB 5 | { 6 | public class Program 7 | { 8 | public static void Main(string[] args) 9 | { 10 | BuildWebHost(args).Run(); 11 | } 12 | 13 | public static IWebHost BuildWebHost(string[] args) => 14 | WebHost.CreateDefaultBuilder(args) 15 | .UseStartup() 16 | .Build(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ServiceA/ServiceA.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | ..\docker-compose.dcproj 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /ServiceB/ServiceB.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | ..\docker-compose.dcproj 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Gateway/Gateway.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | ..\docker-compose.dcproj 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Gateway/Program.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using Microsoft.AspNetCore.Hosting; 3 | using Microsoft.Extensions.DependencyInjection; 4 | 5 | namespace Gateway 6 | { 7 | public class Program 8 | { 9 | public static void Main(string[] args) 10 | { 11 | 12 | IWebHostBuilder builder = new WebHostBuilder(); 13 | 14 | builder.ConfigureServices(s => { 15 | s.AddSingleton(builder); 16 | }); 17 | 18 | builder.UseKestrel() 19 | .UseContentRoot(Directory.GetCurrentDirectory()) 20 | .UseStartup(); 21 | 22 | var host = builder.Build(); 23 | 24 | host.Run(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /docker-compose.dcproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 2.0 5 | Linux 6 | 477b8ed6-df43-4f9c-988c-638cd1cf87a8 7 | True 8 | http://localhost:{ServicePort}/api/values 9 | servicea 10 | 11 | 12 | 13 | 14 | docker-compose.yml 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Gateway/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:50458/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "api/values", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "Gateway": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "launchUrl": "api/values", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | }, 26 | "applicationUrl": "http://localhost:50459/" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ServiceA/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:49743/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "api/values", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "ServiceA": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "launchUrl": "api/values", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | }, 26 | "applicationUrl": "http://localhost:49744/" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ServiceB/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:49754/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "api/values", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "ServiceB": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "launchUrl": "api/values", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | }, 26 | "applicationUrl": "http://localhost:49755/" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ServiceA/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.AspNetCore.Mvc; 3 | 4 | namespace ServiceA.Controllers 5 | { 6 | [Route("")] 7 | public class ValuesController : Controller 8 | { 9 | // GET api/values 10 | [HttpGet] 11 | public IEnumerable Get() 12 | { 13 | return new [] 14 | { 15 | new ServiceAModel{Name = "Google",Url = "https://www.google.com.au"}, 16 | new ServiceAModel{Name = "SSW",Url = "https://www.ssw.com.au"}, 17 | new ServiceAModel{Name = "eBay",Url = "https://www.ebay.com.au/"}, 18 | }; 19 | } 20 | } 21 | 22 | public class ServiceAModel 23 | { 24 | public string Name { get; set; } 25 | public string Url { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ServiceB/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Microsoft.AspNetCore.Mvc; 4 | 5 | namespace ServiceB.Controllers 6 | { 7 | [Route("")] 8 | public class ValuesController : Controller 9 | { 10 | // GET api/values 11 | [HttpGet] 12 | public IEnumerable Get() 13 | { 14 | return new [] 15 | { 16 | new ServiceBModel { Id = Guid.NewGuid(), Subject = "Why Azure?", Body = "..." }, 17 | new ServiceBModel { Id = Guid.NewGuid(), Subject = "Docker is Awesome", Body = "..." }, 18 | new ServiceBModel { Id = Guid.NewGuid(), Subject = "Kubernetes is Amazing", Body = "..." } 19 | 20 | }; 21 | } 22 | } 23 | 24 | public class ServiceBModel 25 | { 26 | public Guid Id { get; set; } 27 | public string Subject { get; set; } 28 | public string Body { get; set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ServiceA/Startup.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using Microsoft.AspNetCore.Hosting; 3 | using Microsoft.Extensions.Configuration; 4 | using Microsoft.Extensions.DependencyInjection; 5 | 6 | namespace ServiceA 7 | { 8 | public class Startup 9 | { 10 | public Startup(IConfiguration configuration) 11 | { 12 | Configuration = configuration; 13 | } 14 | 15 | public IConfiguration Configuration { get; } 16 | 17 | // This method gets called by the runtime. Use this method to add services to the container. 18 | public void ConfigureServices(IServiceCollection services) 19 | { 20 | services.AddMvc(); 21 | } 22 | 23 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 24 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 25 | { 26 | if (env.IsDevelopment()) 27 | { 28 | app.UseDeveloperExceptionPage(); 29 | } 30 | 31 | app.UseMvc(); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ServiceB/Startup.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using Microsoft.AspNetCore.Hosting; 3 | using Microsoft.Extensions.Configuration; 4 | using Microsoft.Extensions.DependencyInjection; 5 | 6 | namespace ServiceB 7 | { 8 | public class Startup 9 | { 10 | public Startup(IConfiguration configuration) 11 | { 12 | Configuration = configuration; 13 | } 14 | 15 | public IConfiguration Configuration { get; } 16 | 17 | // This method gets called by the runtime. Use this method to add services to the container. 18 | public void ConfigureServices(IServiceCollection services) 19 | { 20 | services.AddMvc(); 21 | } 22 | 23 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 24 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 25 | { 26 | if (env.IsDevelopment()) 27 | { 28 | app.UseDeveloperExceptionPage(); 29 | } 30 | 31 | app.UseMvc(); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Gateway/configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "ReRoutes": [ 3 | { 4 | "DownstreamPathTemplate": "/", 5 | "DownstreamScheme": "http", 6 | "DownstreamPort": 80, 7 | "DownstreamHost": "servicea", 8 | "UpstreamPathTemplate": "/a/", 9 | "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Options" ] 10 | }, 11 | { 12 | "DownstreamPathTemplate": "/{everything}", 13 | "DownstreamScheme": "http", 14 | "DownstreamPort": 80, 15 | "DownstreamHost": "servicea", 16 | "UpstreamPathTemplate": "/a/{everything}", 17 | "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Options" ] 18 | }, 19 | { 20 | "DownstreamPathTemplate": "/", 21 | "DownstreamScheme": "http", 22 | "DownstreamPort": 80, 23 | "DownstreamHost": "serviceb", 24 | "UpstreamPathTemplate": "/b/", 25 | "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Options" ] 26 | }, 27 | { 28 | "DownstreamPathTemplate": "/{everything}", 29 | "DownstreamScheme": "http", 30 | "DownstreamPort": 80, 31 | "DownstreamHost": "serviceb", 32 | "UpstreamPathTemplate": "/b/{everything}", 33 | "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Options" ] 34 | } 35 | ], 36 | "GlobalConfiguration": {} 37 | } -------------------------------------------------------------------------------- /Gateway/tempkey.rsa: -------------------------------------------------------------------------------- 1 | {"KeyId":"2f10dc803f62ddb88bcf2bd3c6613be1","Parameters":{"D":"QJQC5TST3gqhIPYRBxgTuRYPowQY0q6NL7irkDpMrclBBHjQGDb7BU10Ww7kS7WH2oIJ4wuzmfV44nq2b7Gm0i8QVIs9QXYJvew2N2UN8blZ9li3qDD4barfThBvEVTp5D9TQUURwHMA6DbN86keJQjqH2EbXVQX8tjKfmKkXSziGL0hiu/nunoyL7Z5qc5e7v00lyDqzP3PIwi1qyF2GVI5NIpVqvfKMcnB0E/nISMuXZNQxHmCIMWEfAGP6YEfE/Gb34tKL2cthccyDSGfqoOHSBjZK0DGqPPKF16EM7pDl8M8gylPR8H0vqSuHapl8zJwDazdwHQo7bd64u5XkQ==","DP":"fZZ03RKAnQEOj5kYdiAQzFnNDdqGej0EDH1k4R9KWWt8cZqeD4EpK/uDvzgSQdwBHHKhDOMnU3CG1UAcUAWUqD56Q1gRPgLDItaEpDBrcFV1Y4pJsQvyEvEvApTwj3guq6JWZQ5uVLUDUnJXrgFNTUNIwDNshFRarEO5cXt67AU=","DQ":"eP+uPCc6XMp+53UtkG8VjZLlO2X9cfJfGDC2bs5hSiVy5lHRpVSG911KXSm7xGIwQD95b08fzpO59SY8s0ubA0j13hQxivaKhY/cIpmVKsRaHy1QlMLxLUWjQbW+Q/TUxMVe6cnI5cqjxv2MgiS937MSCR0mNaB0xN1WaFbnJZ8=","Exponent":"AQAB","InverseQ":"MlpOc4NQB9y2g6lQltNZ4r0oF96lNqsDJg1pyWTkJoXsqr8gIA7IAH3Qcqe+seVxG80T8yyPKbMzwyYYM2FpZ5aEXD0ACOCqLxo9pXP444YtVl3+MfZcA/UU0mGWf96fnfJpxuPXzxJAWWwp7nJsoZ17yX5Rj3pMS1q5IV7V1LU=","Modulus":"yFWLiesGZ9r1QjnZn/3/k+5dg4XmPz9HA3CQvtpr8jWLyYpqgN+We11Z5VTwD2+Zb4fYULk9dQviuQ7FQgr8JQGbFBYHFdPhtIF3yp/ftBX0HvT/QnxV+J+5VywMuId3nc/1iZbOT7ITL2CCB4ByLOvZnU21SX/0c3eR9e6JBoqYr9RFFfJposclctLx5zZ04np2W0E6FqAbqt5+vJ4+g0QF9fH9Pgbl2qZWZfwz7PtCElVO+69SYy5gqK0+zYv40+0jou3k1ckVQGE3IvAdTlk6Ov4S2OMzZ6DgL04Rcj/m4j9d+k59tHv2Z5IY5wSQ+idAmpGvAnJrWxw49qVKAw==","P":"7e2PyuP1MR0WZ9qVlbDLKEFAdjmIXyolpjcGNnP1nXxF3gaGTWMSyHr2Se2VhfwwSH3n20QmvN7Th5p6mFPsxco306ylmvxBquxRkmETLgtOQE57eieda1JX3rK2PmuDYHxXOxF3uUcJPTDhVAIvdIXQJUT4FlNsj2ggxxN1X4U=","Q":"14z7nzO9pJV3+RHerfSkuoV/2jkp8GXFFBaQalxloIh6uGTfJHwy/evRczpo9uCAuScOcc4LhXg9zGkINwC/KLNfeOf4JRN1qeksdjJkf6GepVir+bTDXwZ+/WzhjdS1aHFPydbPUlaBn0xvzwUoDME17/nCqIq+TJK86O1shec="}} -------------------------------------------------------------------------------- /Gateway/Startup.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using Microsoft.AspNetCore.Hosting; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using Microsoft.Extensions.Configuration; 5 | using Ocelot.DependencyInjection; 6 | using CacheManager.Core; 7 | using Ocelot.Middleware; 8 | using Microsoft.Extensions.Logging; 9 | using ConfigurationBuilder = Microsoft.Extensions.Configuration.ConfigurationBuilder; 10 | 11 | namespace Gateway 12 | { 13 | public class Startup 14 | { 15 | public Startup(IHostingEnvironment env) 16 | { 17 | var builder = new ConfigurationBuilder() 18 | .SetBasePath(env.ContentRootPath) 19 | .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) 20 | .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) 21 | .AddJsonFile("configuration.json") 22 | .AddEnvironmentVariables(); 23 | 24 | Configuration = builder.Build(); 25 | } 26 | 27 | public IConfigurationRoot Configuration { get; } 28 | 29 | // This method gets called by the runtime. Use this method to add services to the container. 30 | public void ConfigureServices(IServiceCollection services) 31 | { 32 | services.AddOcelot(Configuration) 33 | .AddCacheManager(x => { 34 | x.WithMicrosoftLogging(log => 35 | { 36 | log.AddConsole(LogLevel.Debug); 37 | }) 38 | .WithDictionaryHandle(); 39 | }); ; 40 | } 41 | 42 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 43 | public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 44 | { 45 | 46 | loggerFactory.AddConsole(Configuration.GetSection("Logging")); 47 | app.UseOcelot().Wait(); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Ocelot.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27004.2009 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceA", "ServiceA\ServiceA.csproj", "{7456FA5E-3C04-4765-86F6-5A2AAAF487AA}" 7 | EndProject 8 | Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{477B8ED6-DF43-4F9C-988C-638CD1CF87A8}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceB", "ServiceB\ServiceB.csproj", "{4973FC0B-B9AF-4CD4-8F2C-1FC5E716AA73}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gateway", "Gateway\Gateway.csproj", "{D592BDFB-4D2D-434B-9FB7-69158FECB862}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {7456FA5E-3C04-4765-86F6-5A2AAAF487AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {7456FA5E-3C04-4765-86F6-5A2AAAF487AA}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {7456FA5E-3C04-4765-86F6-5A2AAAF487AA}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {7456FA5E-3C04-4765-86F6-5A2AAAF487AA}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {477B8ED6-DF43-4F9C-988C-638CD1CF87A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {477B8ED6-DF43-4F9C-988C-638CD1CF87A8}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {477B8ED6-DF43-4F9C-988C-638CD1CF87A8}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {477B8ED6-DF43-4F9C-988C-638CD1CF87A8}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {4973FC0B-B9AF-4CD4-8F2C-1FC5E716AA73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {4973FC0B-B9AF-4CD4-8F2C-1FC5E716AA73}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {4973FC0B-B9AF-4CD4-8F2C-1FC5E716AA73}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {4973FC0B-B9AF-4CD4-8F2C-1FC5E716AA73}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {D592BDFB-4D2D-434B-9FB7-69158FECB862}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {D592BDFB-4D2D-434B-9FB7-69158FECB862}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {D592BDFB-4D2D-434B-9FB7-69158FECB862}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {D592BDFB-4D2D-434B-9FB7-69158FECB862}.Release|Any CPU.Build.0 = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | GlobalSection(ExtensibilityGlobals) = postSolution 41 | SolutionGuid = {D58F47A3-4BA9-40BD-B794-1B43C0D3757F} 42 | EndGlobalSection 43 | EndGlobal 44 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc --------------------------------------------------------------------------------