Код: Выделить всё
public class HistoryLogMiddleware : IFunctionsWorkerMiddleware
{
public async Task Invoke(FunctionContext context, FunctionExecutionDelegate next)
{
var requestData = await context.GetHttpRequestDataAsync();
var body = await new StreamReader(requestData.Body).ReadToEndAsync();
Console.WriteLine($"Request Body: {body}");
await next(context);
var responseData = context.GetHttpResponseData().Body;
var resp = await new StreamReader(responseData).ReadToEndAsync();
Console.WriteLine($"Response: {resp}");
}
}
Код: Выделить всё
[assembly: FunctionsStartup(typeof(Startup))]
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddDatabases();
builder.Services.AddExternals();
builder.Services.AddUseCases();
builder.Services.AddSingleton();
}
}
Моя функция:
Код: Выделить всё
public class RegisterClientFunction
{
private readonly IClientsDomain _clientsDomain;
public RegisterClientFunction(IClientsDomain clientsDomain)
{
_clientsDomain = clientsDomain;
}
[FunctionName(nameof(RegisterClientFunction))]
public async Task Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
var data = JsonConvert.DeserializeObject(requestBody);
var resp = await ExecuterDomain.ExecuteAsync(() => _clientsDomain.RegisterClient(data));
return new ObjectResult(resp);
}
}
[img]https:/ /i.sstatic.net/fMd79O6t.png[/img]
Подробнее здесь: https://stackoverflow.com/questions/784 ... -invokated
Мобильная версия