Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameterless constructor error with EventHandler #308

Closed
Reikooters opened this issue Oct 31, 2022 · 1 comment
Closed

Parameterless constructor error with EventHandler #308

Reikooters opened this issue Oct 31, 2022 · 1 comment
Labels
bug Something isn't working fixed the bug has been squashed

Comments

@Reikooters
Copy link

Hi there,

I'm getting the following error on startup when trying to use Event Handlers: Cannot dynamically create an instance of type. Reason: No parameterless constructor defined.

image

My project is a brand new project where I copied the DTO, Handler, Request and Endpoint classes as per the documentation just to try it out, as I have a use case in a real project where this seems like it would suit my needs perfectly (need to respond quickly with OK to a request, then fire and forget a task that may take 4-8 seconds). https://fast-endpoints.com/docs/event-bus#_1-define-an-event-model-dto

using System;

namespace FastEndpointsEventHandlerDemo.Features.Order
{
    public class OrderCreationHandler : IEventHandler<OrderCreatedEvent>
    {
        private readonly ILogger _logger;

        public OrderCreationHandler(ILogger<OrderCreationHandler> logger)
        {
            _logger = logger;
        }

        public Task HandleAsync(OrderCreatedEvent eventModel, CancellationToken ct)
        {
            _logger.LogInformation($"order created event received:[{eventModel.OrderID}]");
            return Task.CompletedTask;
        }
    }
}

If I add a parameterless constructor as per the error, then I can't use constructor dependency injection.

I'm using the lastest version 5.3.0.1-beta. Was there a change that hasn't been documented yet?

Also, the search box on the documentation isn't working (never produces any results)

dj-nitehawk added a commit that referenced this issue Oct 31, 2022
@dj-nitehawk dj-nitehawk added bug Something isn't working fixed the bug has been squashed labels Oct 31, 2022
@dj-nitehawk
Copy link
Member

oops... looks like i forgot to delete an unneeded line from the old code.
fixed in v5.3.1
thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed the bug has been squashed
Development

No branches or pull requests

2 participants