Add MqttRoutingOptions.FromAssemblies to support explicit controller assembly discovery#16
Open
Phenek wants to merge 1 commit intoIoTSharp:masterfrom
Open
Add MqttRoutingOptions.FromAssemblies to support explicit controller assembly discovery#16Phenek wants to merge 1 commit intoIoTSharp:masterfrom
Phenek wants to merge 1 commit intoIoTSharp:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds
FromAssembliestoMqttRoutingOptionssoAddMqttControllers()can use explicit assembly discovery rather than relying on defaultAssembly.GetEntryAssembly().In containerized integration tests (e.g., WebApplicationFactory), GetEntryAssembly() is the test host project, which often does not include our MQTT controller types ([MqttController]). As a result, routing table is empty and MQTT messages are seen as "not consumed" even though controller methods exist.
Changes included
ServiceCollectionExtensions (MQTTnet.AspNetCore.Routing)
new method:
public static MqttRoutingOptions FromAssemblies(this MqttRoutingOptions opt, params Assembly[] assemblies) { opt.FromAssemblies = assemblies; return opt; }Why this matters
Fixes non-deterministic route discovery in integration tests.
Matches behavior of ASP.NET MVC/Endpoint routing where explicit route assembly source is supported.
Required for test frameworks where entry assembly is not the web app object.
Example usage
services.AddMqttControllers(opt => { opt.FromAssemblies(typeof(Startup).Assembly); });