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

Consider adding multiple ways to use this library #18

Open
sander1095 opened this issue Oct 20, 2021 · 0 comments
Open

Consider adding multiple ways to use this library #18

sander1095 opened this issue Oct 20, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@sander1095
Copy link
Owner

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

  • Add the HATEOAS action filter to your MVC filters
  • Make one of your DTO's derive from HateoasObject or implement IHateoasObject
  • Implement the IHateoasProvider<> (or async version) for your DTO.

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

  • Less invasion of a user's projects.
  • I personally like using nswag to generate API Clients. WIthout attributes, it might be more difficult to make the api client generator add the HATEOAS properties (links) back to the generated DTO's. Perhaps something with OpenApi could be done?
  • Reflection is possibly slow! But I think we already use reflection right now, anyway, so how much does it matter?

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

  • Less invasion of a user's projects.
  • I personally like using nswag to generate API Clients. WIthout attributes, it might be more difficult to make the api client generator add the HATEOAS properties (links) back to the generated DTO's. Perhaps something with OpenApi could be done?
  • Reflection is possibly slow! But I think we already use reflection right now, anyway, so how much does it matter?
  • Less flexible than the provider approach.

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.

  • Do users think something is wrong with the current approach? Could we instead improve our current approach instead of adding more options?
  • Consider all the trade offs (complexity, performance, "fitting in" with ASP.NET Core's code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant