Ocelot IHostBuilder and IWebHostBuilder issues

Created on 30 Oct 2019  路  2Comments  路  Source: ThreeMammals/Ocelot

Expected Behavior / New Feature

Hi,

I'm having this issue after updating my system to .Net Core 3.0

image

I need to dynamically create ocelot.json base on my environment but I'm getting this error
"cannot convert from Microsoft.Extension.Hosting.IHostEnvironment to Microsoft.AspNetCore.Host.IWebHostEnvironment"

I find out that ocelot is still using IWebHostBuilder which is for .Net core 2.x instead of IHostBuilder that comes with .Net cor 3.0.

Thanks in advance

Most helpful comment

You can use ConfigureWebHostDefaults to do that.

Here is a sample that you can take a look.

public static IHostBuilder CreateHostBuilder(string[] args) =>
              Host.CreateDefaultBuilder(args)
                 .ConfigureWebHostDefaults(webBuilder =>
                 {
                     webBuilder.UseUrls("http://*:9000")
                       .ConfigureAppConfiguration((hostingContext, config) =>
                       {
                           config
                               .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
                               .AddJsonFile("ocelot.json")
                               .AddEnvironmentVariables();

                           config.AddOcelot("your folder", hostingContext.HostingEnvironment);

                       })
                      .ConfigureServices(services =>
                      {
                          services.AddOcelot();
                      })
                     .Configure(app =>
                     {
                         app.UseOcelot().Wait();
                     });
                 });            

All 2 comments

You can use ConfigureWebHostDefaults to do that.

Here is a sample that you can take a look.

public static IHostBuilder CreateHostBuilder(string[] args) =>
              Host.CreateDefaultBuilder(args)
                 .ConfigureWebHostDefaults(webBuilder =>
                 {
                     webBuilder.UseUrls("http://*:9000")
                       .ConfigureAppConfiguration((hostingContext, config) =>
                       {
                           config
                               .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
                               .AddJsonFile("ocelot.json")
                               .AddEnvironmentVariables();

                           config.AddOcelot("your folder", hostingContext.HostingEnvironment);

                       })
                      .ConfigureServices(services =>
                      {
                          services.AddOcelot();
                      })
                     .Configure(app =>
                     {
                         app.UseOcelot().Wait();
                     });
                 });            

You can use ConfigureWebHostDefaults to do that.

Here is a sample that you can take a look.

public static IHostBuilder CreateHostBuilder(string[] args) =>
              Host.CreateDefaultBuilder(args)
                 .ConfigureWebHostDefaults(webBuilder =>
                 {
                     webBuilder.UseUrls("http://*:9000")
                       .ConfigureAppConfiguration((hostingContext, config) =>
                       {
                           config
                               .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
                               .AddJsonFile("ocelot.json")
                               .AddEnvironmentVariables();

                           config.AddOcelot("your folder", hostingContext.HostingEnvironment);

                       })
                      .ConfigureServices(services =>
                      {
                          services.AddOcelot();
                      })
                     .Configure(app =>
                     {
                         app.UseOcelot().Wait();
                     });
                 });            

Thanks, you've saved my day.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mogliang picture mogliang  路  3Comments

FerAguilarR93 picture FerAguilarR93  路  6Comments

mjrousos picture mjrousos  路  6Comments

nagybalint001 picture nagybalint001  路  4Comments

Marusyk picture Marusyk  路  3Comments