jamescrosswell / CommandRouting

A DNX alternative to MVC that lets you route directly to CQRS style command handlers.
MIT License
3 stars 3 forks source link

I want to be able to use attributes to configure Command Routes #1

Open jamescrosswell opened 8 years ago

jamescrosswell commented 8 years ago

For example:

[CommandRoute(typeof(IgnoreBob), typeof(SayHello))]

We could also decorate the command handlers with HTTP Verb attributes to add route constraints... although I think I might prefer descendent attributes like GetCommandRouteAttribute and PostCommandRouteAttribute

bruno-garcia commented 8 years ago

Based on your signature, the constructor of CommandRoute would have to take params Type[] commandHandlers That also means that passing no argument will compile just fine. The problem with that is that a CommandRoute without any CommandHandler is an invalid declaration. And removing the 'params' means the usage will require: new [] { typeof(T), typeof(T2) }. I'd say it's fine to keep the params but now that we can have an Attribute missing a handler, what to do?

I see two ways: 1 - Throw when loading the attributues and 2- Take an ILogger (https://github.com/aspnet/Logging) and log Warning when we find RouteAttribute without Handler. Surely there's the third option: Simply ignore that attribute, which might be painful for troubleshooting.

jamescrosswell commented 8 years ago

Yeah I thought about pipelines with no handlers. Basically in that case context.IsHandled will never be set to true in the call to IRouter.Task RouteAsync(RouteContext context);. Technically, that's not a problem for OWIN - it'll just keep walking through the remaining middleware until it [perhaps] finds something else that can handle the request... In practice, I can't think of any reason why someone would want to register a command route to a pipeline with no handlers. I think probably we could throw an ArgumentException or something in that case. It's probably better than logging and getting more cryptic errors/issues later on. What do you think?

bruno-garcia commented 8 years ago

It seems to me that it's no one intention to have a Route created, mapped to a Request without any Handler defined. It's probably a configuration issue. Wouldn't it be appropriate to throw during Router.Build() instead? There will be more situations to throw (e.g.: same routeTemplate defined to multiple Requests)

jamescrosswell commented 8 years ago

Sure - I think the earlier the problem gets detected and throws an exception the better.

bruno-garcia commented 8 years ago

There's a branch: attribute-routing with a first version Requests are decorated with RouteRequestAttribute, derived types can define the HTTP verb (there's GET and POST so far). Calling AddAttriibuteRouting will find all usages of the attribute and call AddRoute based on those.

jamescrosswell commented 8 years ago

Cheers man. Merged into master (along with the command sets branch)