You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
You are correct Grace is interpreting that to mean please export the type CommandHandler<> which as you say is abstract and can't be created. Grace does have a bulk registration feature that works on an enumeration of types as well as some helper extension methods for use like ExportAssemblyContaining<T>.
For the moment it looks like you can register your commands like this.
Normally I would suggest the syntax below but it seems there is a small bug in the bulk registration for ByInterface when doing generic interfaces (it exports only open generic implementations currently). I'm going to check in a fix for this right now but it won't be available till next release.
Activity
ipjohnson commentedon Jan 30, 2018
Hi @davidkeaveny
You are correct Grace is interpreting that to mean please export the type
CommandHandler<>which as you say is abstract and can't be created. Grace does have a bulk registration feature that works on an enumeration of types as well as some helper extension methods for use likeExportAssemblyContaining<T>.For the moment it looks like you can register your commands like this.
Normally I would suggest the syntax below but it seems there is a small bug in the bulk registration for ByInterface when doing generic interfaces (it exports only open generic implementations currently). I'm going to check in a fix for this right now but it won't be available till next release.
fix generic bulk ByInteface problem for issue #148
davidkeaveny commentedon Jan 31, 2018
Thanks, your provided code sample works just fine for me.
I'll look out for the
ByInterfacefix when it comes.ipjohnson commentedon Feb 16, 2018
@davidkeaveny I'm going to close this out and plan to do a release in the next couple days. If you have any other issue let me know.