Skip to content

Add MqttRoutingOptions.FromAssemblies to support explicit controller assembly discovery#16

Open
Phenek wants to merge 1 commit intoIoTSharp:masterfrom
Phenek:master
Open

Add MqttRoutingOptions.FromAssemblies to support explicit controller assembly discovery#16
Phenek wants to merge 1 commit intoIoTSharp:masterfrom
Phenek:master

Conversation

@Phenek
Copy link
Copy Markdown

@Phenek Phenek commented Apr 1, 2026

This PR adds FromAssemblies to MqttRoutingOptions so AddMqttControllers() can use explicit assembly discovery rather than relying on default Assembly.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); });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant