sander1095 / munisio

A modern HATEOAS library for .NET to reduce your client-side validation
MIT License
8 stars 4 forks source link

Consider adding multiple ways to use this library #18

Open sander1095 opened 2 years ago

sander1095 commented 2 years ago

Currently to use this library, you have to perform the following steps:

This is pretty clean, pretty OOP and very testable. But you could also argue it's kind of verbose and "ugly" that my library requires that a user changes their DTO's.

What if we could have some alternative approaches on using this library in your codebase? The user could then choose which version they like best. One immediate downside of this feature would be added complexity to the codebase, and perhaps also for the user. Instead of having 1 implementation they can now choose multiple options. If there are too many options, it might become annoying because different codebases will implement things in different ways.

I could come up with multiple alternatives:

Use attributes on the DTO instead of HATEOAS

Instead of making classes inherit from DTO, Provide some attribute like [HateoasObject] or [HateoasCollection] that people can put on their DTO's. Our library would then look for these and add links to the DTO at runtime.

Tradeoffs

Use attributes on the Controller Action instead of the DTO

Inspired by [Produces] that you can put on a controller, what if we have something like [Hateoas(href, action, rel)] that you put on a controller's action which indicates that this method returns some hateaoas link? Perhaps the attribute could even have a Policy or Role property that could be used to determine if the link should be added! This way, you do not need to edit your DTO's at all! You might not even need the hateoas providers anymore!

Tradeoffs

Ending

It is important that some discussions take place about these options, and I think the library has to be in use for a while before we really know if this is a good idea.