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

Some types do not get decorated #214

Open
dario-l opened this issue Oct 6, 2023 · 2 comments
Open

Some types do not get decorated #214

dario-l opened this issue Oct 6, 2023 · 2 comments

Comments

@dario-l
Copy link

dario-l commented Oct 6, 2023

I have a very strange symptom. Some classes (CommandHandlers) have been decorated and others with exactly the same structure, located in a different directory (different namespace) are not.

I have no idea where to look for the cause.

The class structure is as follows:

internal static class Create
{
    public record Command( ... ) : ICommand<int>;

    public class CommandHandler : ICommandHandler<Command, int>
    {
        ...
    }
}

Dispatcher looks like this:

    public async Task<TResult> SendAsync<TResult>(ICommand<TResult> command, CancellationToken token = default)
    {
        var handlerType = typeof(ICommandHandler<,>).MakeGenericType(command.GetType(), typeof(TResult));
        using var scope = _serviceFactory.CreateScope();
        var handler = scope.ServiceProvider.GetRequiredService(handlerType);

         ...
    }

Registration:

        builder.Services.Scan(s => s.FromAssemblies(assemblies)
            .AddClasses(c =>
            {
                c.AssignableToAny(
                        typeof(ICommandHandler<,>),
                        typeof(ICommandHandler<>),
                        typeof(IQueryHandler<,>),
                        typeof(IEventHandler<>))
                    .WithoutAttribute<DecoratorAttribute>();
            }, false)
            .AsImplementedInterfaces()
            .WithScopedLifetime());

I have absolutely no idea why decorating works that inconsistently. 😢

@khellang
Copy link
Owner

khellang commented Oct 6, 2023

Hey @dario-l! 👋🏻

I don't know what to tell you; it sounds weird to me too, but until I have a repro, there's not much I can do with the little information I have from this issue 😔

@dario-l
Copy link
Author

dario-l commented Oct 10, 2023

Hi @khellang
Thanks for the response. I'm just imbecil but I will write my experience with that.

All handlers have the following generic constraints: class, IMessage but becouse of my stupidness I slap on my decorators also constraint new().

Because of this, decorators only worked on messages that had an empty/default constructor.

From my perspective some works but some other do not. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants