Search code examples
c#.netswaggerfast-endpoints

fast endpoint defined in another dll project does not work


I forked ardalis git repo Clean Architecture. In SharePrompts.Web project there are some fast endpoints for contributor entity.

I created a new dll project SharePrompts.Web.Cap and added a single fast endpoint that creates post entity:

public class CreateEndpoint(IMediator _mediator) : Endpoint<CreatePostRequest, CreatePostResponse>
{
  public override void Configure()
  {
    Post("/posts");
    AllowAnonymous();
  }

  public override async Task HandleAsync(CreatePostRequest req, CancellationToken ct)
  {
    var result = await _mediator.Send(new CreatePostCommand(req.Title, req.Text, req.Tag, req.UserId), ct);

    if (result.IsSuccess)
    {
      Response = new CreatePostResponse(result.Value.Id, req.Title, req.Text, req.Tag);
      return;
    }
  }
}

SharePrompts.Web references to SharePrompts.Web.Cap project.

But the problem is that an endpoint which was added in SharePrompts.Web.Cap project neither can be invoked (returns 404 error) nor is visible on swagger page.

How can I resolve this issue?


Solution

  • you need to inform fastendpoints where to find endpoints located in different assemblies like so:

    builder.Services.AddFastEndpoints(
        o => o.Assemblies = new[]
        {
            typeof(SomeAssemblyName).Assembly,
            typeof(AnotherAssemblyName).Assembly
        });