Skip to content

Replace interceptor with source-generated extension method #22

Merged
mattmercurio merged 5 commits intomainfrom
replace-interceptor-with-generated-extension
Feb 23, 2026
Merged

Replace interceptor with source-generated extension method #22
mattmercurio merged 5 commits intomainfrom
replace-interceptor-with-generated-extension

Conversation

@mattmercurio
Copy link
Collaborator

  • Generate AddNServiceBusFunctions() directly into the host project instead of intercepting a placeholder
  • Detect host project MSBuild properties
  • Add warning when endpoint registrations exist but AddNServiceBusFunctions() is not called

@mattmercurio mattmercurio self-assigned this Feb 18, 2026
@mattmercurio mattmercurio marked this pull request as ready for review February 18, 2026 22:30
sb.AppendLine(" }");
sb.AppendLine("}");
sb.AppendLine();
sb.AppendLine("namespace NServiceBus");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be put into the user namespace instead so that it doesn't clash?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using RootNamespace property and captured that on the board for packaging items. Unless we should do another way such as compilation.Assembly.Name?

sb.AppendLine("namespace NServiceBus");
sb.AppendLine("{");
sb.AppendLine(" static file class NServiceBusFunctionsInterceptors");
sb.AppendLine(" [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiousity: Why browsable state never?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeaaa. That would have been quite obvious to a user I suppose.

});
}

static bool HasAutoGeneratedRegistrationTypes(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a stupid question. I only had limited time today to look at this. I was wondering given the generator generates a well know type in a well known namespace couldn't we simply check for the metadata to exist?


if (nodeContext.Node is InvocationExpressionSyntax
{
Expression: MemberAccessExpressionSyntax
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would also fire and flip the call found for similar method names, and you probably would have to check whether it is the real method you are looking for

@danielmarbach
Copy link
Contributor

@mattmercurio unfortunately this might require some rebasing

Copy link
Contributor

@danielmarbach danielmarbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed it today. Pre-approving since we want to further iterate on things anyway over time this is good enough for now.

@mattmercurio mattmercurio force-pushed the replace-interceptor-with-generated-extension branch from b940fbb to d23c600 Compare February 23, 2026 20:00
@mattmercurio mattmercurio merged commit b1eeeda into main Feb 23, 2026
1 check passed
@mattmercurio mattmercurio deleted the replace-interceptor-with-generated-extension branch February 23, 2026 21:15
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.

3 participants