I am currently trying to make a request to a third party library in my ASP.NET Core 6 Web API and work with this data (it really has to run over a Web API template).
That means I'm importing data from another API.
Unfortunately I don't know how to tell my application to make a call.
I would have expected the Task to run automatically when the application starts. Unfortunately this is not the case.
I first wanted to test whether this works at all when the application is started. Later, I would build in a scheduler, which sends requests accordingly.
It should be possible, right?
It would be great if someone could tell me as well if it's possible to put the URL "localhost:xxx/" in the constructor somehow, but still not get any dependency injection errors with AddScoped.
I use Flurl.Http to make Http Requests.
If it is important. My program.cs is in a console application and DataImport in an empty project
Unfortunately, I am relatively new to the ASP.NET world and I hope that the question is not too unprofessional. Otherwise I apologize. It's kind of hard to google for a problem like this and find something
using Flurl;
using Flurl.Http;
public class DataImport
{
private readonly Service service;
public DataImport(Servie service)
{
_service = service;
}
public async Task<IEnumerable<Data>> ImportData()
{
var data = await "localhost:xxx/".AppendPathSegment("data").GetJsonAsync<DataDto[]>();
return _service.Add(data.Select(it => new DatoDtoToData(it)));
}
}
program.cs:
builder
.Services
... Service Injections
....
.AddScoped<DataImport>()