ThreeMammals / Ocelot

.NET API Gateway
https://www.nuget.org/packages/Ocelot
MIT License
8.37k stars 1.64k forks source link

'ConfigureDevelopment' or 'Configure' could not be found #62

Closed juancash closed 7 years ago

juancash commented 7 years ago

I´m following the documentation to build an api gateway with Ocelot. I created a simple solution with two API, the APIGateway and the API1 (both with the Visual Studio Api template) with the target to try to redirect the requests. I have some questions:

  1. My first question is about the line

services.AddOcelot(Configuration);

in ConfigureServices method from Startup class. This method AddOcelot is not available. I´m using:

 services.AddOcelotOutputCaching(settings);
 services.AddOcelotFileConfiguration(Configuration);
 services.AddOcelot();

is this correct?

  1. When I run the project I get the following error if I use the code of the documentation in the Main method (class Program) when executes line:

var host = builder.Build();

System.InvalidOperationException: 'A public method named 'ConfigureDevelopment' or 'Configure' could not be found in the 'OcelotTest.Startup' type.'

If I use the code by default, seems run OK.

            var host = new WebHostBuilder()
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .UseApplicationInsights()
                .Build();

            host.Run();

It´s possible use this code or will affect in something in the future?

  1. For now I have achieved my goal with this code. It is surprising that with the use of Ocelot you can have an ApiGateway with so little code. Congratulations.

Now I will try to use it with my IdentityServer, although I have to investigate a bit since I am very new to these two tools.

  1. The performance is affected by the number of entries in configuration.json or is it controlled?

Thanks for your time.

TomPallister commented 7 years ago

@jsantanainel Please look at https://github.com/TomPallister/Ocelot/wiki/Startup for the startup class. Ocelot doesnt use services.AddOcelotFileConfiguration(Configuration); anymore.

Im curious where did you find the documentation for that as it must be out of date.

you might want to change your Program.cs to be the same as in the Startup example as well!

Also sometimes documentation is wrong by mistake so this is a good guide...

https://github.com/TomPallister/Ocelot/blob/develop/test/Ocelot.ManualTest/Startup.cs https://github.com/TomPallister/Ocelot/blob/develop/test/Ocelot.ManualTest/Program.cs

juancash commented 7 years ago

@TomPallister Yes I´m following that wiki. But in the version 1.3.2 of Ocelot (that is the last in Nuget) is not available an AddOcelot method with parameters.

TomPallister commented 7 years ago

@jsantanainel I a mistake and have not updated the readme before I made the release. I might do a new release now to correct the mistake.

juancash commented 7 years ago

@TomPallister No problem. Thanks.

TomPallister commented 7 years ago

@jsantanainel To answer question 4. Yes the performance is effected by by the number of entries in configuration.json. This is something that I would like to improve.

At the moment the code goes for each reroute, does that re route match the upstream Http request path, if it does then use it. The match is done using a regex that is built from the reroute entry in configuration.json at runtime based on what has been entered in UpstreamTemplatePath e.g. /products/{productId}/ becomes /products/.*/ so if you request /products/1/ it will match.

Obvious problem is looping through each entry to find a match as the more you look through the more you are matching which will effect performance.

I have taken a lean approach to building Ocelot doing the least I can to get a feature working with the idea we will come back and optimise later. The code has been written with performance in mind so it should not be too slow.

If you would like to investigate this and improve the code that would be awesome!

juancash commented 7 years ago

@TomPallister Perfect, we keep in touch.