-1

クリーン アーキテクチャで asp.net コア Web API 6.0 プロジェクトを実装しました。 https://github.com/jasontaylordev/CleanArchitecture

すべての API は開発モードで正常に動作しています。しかし、本番モードの API は機能しません。

例: 郵便配達員 http://localhost:5000/api/deals/public?SiteCode=wpf を介して get 要求を送信しました。

そして、500エラーが発生しました。 { "type": "https://tools.ietf.org/html/rfc7231#section-6.6.1", "title": "An error occurred while processing your request.", "status": 500 }

ターミナルでは、出力は次のように表示されます

 Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[62]
      User profile is available. Using '/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: techne-bo-for-ota/
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/1.1 GET http://localhost:5000/api/deals/public?SiteCode=wpf - -
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
      Executing endpoint 'WebApi.Controllers.Public.PublicDealController.ListBySiteCode (WebApi)'
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[3]
      Route matched with {action = "ListBySiteCode", controller = "PublicDeal"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.ActionResult`1[Application.Deals.Queries.GetDealListBySiteCode.DealListBySiteCodeVm]] ListBySiteCode(Application.Deals.Queries.GetDealListBySiteCode.GetDealListBySiteCodeQuery) on controller WebApi.Controllers.Public.PublicDealController (WebApi).
info: Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor[1]
      Executing ObjectResult, writing value of type 'Microsoft.AspNetCore.Mvc.ProblemDetails'.
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[2]
      Executed action WebApi.Controllers.Public.PublicDealController.ListBySiteCode (WebApi) in 292.3075ms
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
      Executed endpoint 'WebApi.Controllers.Public.PublicDealController.ListBySiteCode (WebApi)'
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished HTTP/1.1 GET http://localhost:5000/api/deals/public?SiteCode=wpf - - - 500 132 application/problem+json;+charset=utf-8 487.1733ms

program.cs で

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers(options =>
                options.Filters.Add<ApiExceptionFilterAttribute>())
                    .AddFluentValidation()
.AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

var app = builder.Build();

app.UseEndpoints(endpoints =>
{
    endpoints.MapControllers();
});

ApiControllerBase.cs

[ApiController]
[Route("api/[controller]")]
public abstract class ApiControllerBase : ControllerBase
{
    private ISender _mediator = null!;

    protected ISender Mediator => _mediator ??= HttpContext.RequestServices.GetRequiredService<ISender>();
}

PublicDealController.cs

[Route("api/deals/public")]
[AllowAnonymous]
public class PublicDealController : ApiControllerBase
{
    [HttpGet]
    [ProducesResponseType(StatusCodes.Status200OK)]
    [ProducesResponseType(StatusCodes.Status500InternalServerError)]
    public async Task<ActionResult<DealListBySiteCodeVm>> ListBySiteCode([FromQuery] GetDealListBySiteCodeQuery query)
    {
        var result = await Mediator.Send(query);

        return Ok(result);
    }
}

私がした間違いは何ですか?API が本番モードで機能しない理由。誰もがこの問題に直面しましたか? 間違い探しにお役立てください。API がプロダクション モードでのみ動作しない理由がわかりません。

4

0 に答える 0