Skip to content

Bulk registration of open generics #148

@davidkeaveny

Description

@davidkeaveny

I am writing a WebAPI that uses CQRS, and I want to be able to register all implementations of CommandHandler<T> in a set of given assemblies. It looks like open generic registration is implemented like this:

registrations.Export(typeof(CommandHandler<>))
    .As(typeof(ICommandHandler<>));

Am I heading in the right direction, and how can I auto-register all implementations of CommandHandler<T> in a given set of assemblies?

Update : actually, the above doesn't work in my situation; CommandHandler<T> is an abstract base class used by the actual command handlers, and as such it has a protected constructor with a single parameter. Grace complains that the class doesn't have a public constructor, and fails the resolution. If I register individual command handlers individually, then everything works fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions