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

Provide public API for introspecting the MqttRouteTable #7

Open
m-wild opened this issue Jul 23, 2021 · 4 comments
Open

Provide public API for introspecting the MqttRouteTable #7

m-wild opened this issue Jul 23, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@m-wild
Copy link

m-wild commented Jul 23, 2021

Hello everyone,

I am the maintainer of Saunter (https://github.com/tehmantra/saunter) - an AsyncAPI documentation generator (https://www.asyncapi.com/).
Saunter works similarly to MQTTnet.AspNetCore.AttributeRouting, the user adds attributes to their code which describe the publishing or subscribing behavior which the code will implement.

I'd like to be able to provide an integration between Saunter and MQTTnet.AspNetCore.AttributeRouting so that we can re-use the attributes provided by MQTTnet.AspNetCore.AttributeRouting to produce the AsyncAPI document. This will allow the user to simply add Saunter to their project and have documentation produced without having to duplicate attributes like [MqttController] and [MqttRoute].

To do this I need public access to the MqttRouteTable (or some public interface on top of the implementation).

I've currently implemented a proof-of-concept of this feature using reflection and, while ugly, it works.
Please see this issue for details: asyncapi/saunter#101 (comment)

Is this something you would consider adding to the project?

/cc @Rikj000

@avishnyak
Copy link
Contributor

I did some research and it looks like the way to accomplish this in AspNet Core is via ActionDescriptors.

See: https://stackoverflow.com/questions/41908957/get-all-registered-routes-in-asp-net-core
Implementation: https://github.com/kobake/AspNetCore.RouteAnalyzer/blob/master/AspNetCore.RouteAnalyzer/Inner/RouteAnalyzerImpl.cs

I'm leaning towards creating a readonly collection similar to ActionDescriptionCollectionProvider.

I'll try a few things over the next week to see what makes the most sense.

Probably goes without saying, but I would not recommend the reflection route because there is no guarantee that will work into the future (though I have no plans to rewrite the internals on the roadmap right now).

@avishnyak avishnyak added the enhancement New feature or request label Jul 26, 2021
@m-wild
Copy link
Author

m-wild commented Jul 26, 2021

Thanks @avishnyak !
Exposing it via a readonly collection sounds great.

We will not proceed with the reflection-based approach - this was just a proof of concept to see if we had enough information provided by MQTTnet.AspNetCore.AttributeRouting :)

@m-wild
Copy link
Author

m-wild commented Aug 12, 2021

Hi again @avishnyak
Would you be happy to accept a PR if I were to implement this feature?

Thanks

@avishnyak
Copy link
Contributor

Absolutely. My only request would be to ensure that you don't expose the internal routetable implementation. Rather, I would propose that we create a ReadOnly collection with a customer-friendly API.

When thinking about your usecase, my concern was you are asking for me to expose the pointer to the actual action as well as the metadata. In the customer-friendly API, I would propose that we only surface a property which will use reflection to return a MethodImpl and let the consumer take it from there rather than exposing our internal plumbing.

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

2 participants