I'm playing with Carter and so far it works fine, but I have an issue when I want to pass logger (for now its NullLogger, later on I will replace it with something more menaingful).
System.InvalidOperationException: An action cannot use both form and JSON body parameters.
Below is the list of parameters that we found:
Parameter | Source
---------------------------------------------------------------------------------
file | Form File (Inferred)
logger | Body (Inferred)
How do I pass ILogger
from Microsoft.Extensions.Logging.Abstractions
and other things that I would have in builder.Services into Carter endpoints?
Here is my code:
using Carter;
using Microsoft.Extensions.Logging.Abstractions;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddLogging(l => l.AddProvider(NullLoggerProvider.Instance));
builder.Services.AddCarter();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.MapCarter();
app.UseHttpsRedirection();
app.Run();
And here is the controller:
using Carter;
namespace RESTDemo.Controllers
{
public class ParseController : ICarterModule
{
public void AddRoutes(IEndpointRouteBuilder app)
{
var group = app.MapGroup("api/parse");
group.MapPost("", ParseFile).DisableAntifery();
}
private IResult ParseFile(IFormFile file, ILogger logger)
{
logger.LogInformation("ParserExecuted");
return Results.Ok();
}
}
}