0

I am pretty new to .net and also minimal API's. I am trying to create a web API that calls another API. The Fuel Controller is the API that I will be calling and after dependency injection I am trying to call it with the app.MapGet() function which should return the results. Below is my program.cs

IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices((context, services) =>
{
    services.AddEndpointsApiExplorer();
    services.AddSwaggerGen();
        

    services.AddOptions<FuelControllerOptions>()
    .Bind(context.Configuration.GetSection("FuelControllerSettings"));


    services.AddSingleton<IFuelController, FuelController>();


    services.AddHostedService<Worker>();
}).Build();


var builder = WebApplication.CreateBuilder(args);


var app = builder.Build();
ILogger logger = app.Logger;

app.MapGet("/", (FuelController fc) =>
{
    

});
Skin
  • 9,085
  • 2
  • 13
  • 29
svalaie
  • 73
  • 7
  • What is the sense? Usually you have services for that, which can be called from multiple controllers – Lonli-Lokli Nov 15 '22 at 22:49
  • To call other APIs you would typically use a `HttpClient`. Here is a tutorial with examples: https://www.learmoreseekmore.com/2021/12/dotnet6-different-httpclient-techniques-to-consume-thirdparty-api-calls-in-minimal-api.html – Peter B Nov 15 '22 at 22:50
  • 2
    When you say "call another API", most people understand that to mean making a new HTTP request to an entirely separate app. I get the sense that's not what you want to achieve here. Instead, you've got some logic in one endpoint of your app that you want to call from another endpoint. Generally what we do in those situations is abstract the common logic into a separate class, then both endpoints can call that class. – mason Nov 16 '22 at 00:31
  • This application setup is a little confusing, it's creating 2 application (and configuring 2 different DI containers). How did you land here? – davidfowl Dec 22 '22 at 23:19

0 Answers0