Skip to content

feat: Source generator for Cloud Events#75

Open
tsutomi wants to merge 12 commits into
mainfrom
69-cloudevent-factory-source-generator
Open

feat: Source generator for Cloud Events#75
tsutomi wants to merge 12 commits into
mainfrom
69-cloudevent-factory-source-generator

Conversation

@tsutomi

@tsutomi tsutomi commented May 3, 2026

Copy link
Copy Markdown
Member

This pull request primarily adds a new sample demonstrating the use of source generators for event publishing with MassTransit, and improves documentation and build tooling for samples. It also updates the ASP.NET publisher sample to use binary references and provides dedicated build scripts for its dependencies.

New sample: Event generation with MassTransit

  • Added a new sample (event-genration) that demonstrates source-generated IEventConvertible event classes using [Event] annotations and publishing via MassTransit, including documentation and a walkthrough of assembly-level generator attributes. [1] [2] [3] [4]

Documentation improvements

  • Expanded conceptual docs to explain how assembly-level attributes ([EventDataSchemaUri], [EventJsonSerializationOptions]) affect source-generated event code, including schema URI and JSON serialization resolution. [1] [2]
  • Added a detailed README for the ASP.NET publisher sample, describing architecture, prerequisites, and dependency management.

Sample build tooling

  • Introduced dedicated build scripts (build-libs.sh, .ps1, .bat) for the ASP.NET publisher sample, which delegate to shared core scripts to build and copy required binaries into a libs folder. [1] [2] [3]
  • Updated the sample’s project file to reference binaries from the libs folder instead of using project references.

Solution/project structure

  • Added new projects for the event generator and its tests to the solution, including configuration for build and solution folders. [1] [2] [3]
    This pull request introduces a new sample demonstrating source-generated event publishing with MassTransit, updates documentation to explain new generator features, and improves the build/dependency management for samples. It also adds two new projects to the solution for the event generator and its tests, and refines how dependencies are referenced in the ASP.NET publisher sample.

New sample and documentation:

  • Added a new sample, event-genration, showing how to use [Event] source generation with MassTransit, including assembly-level generator attributes for schema URI and JSON serialization options. Documentation for this sample is included and linked from relevant indexes. [1] [2] [3] [4]

  • Expanded documentation to explain the new assembly-level generator attributes (EventDataSchemaUri and EventJsonSerializationOptions) and how the generator resolves schema URIs and JSON options at compile-time or runtime. [1] [2]

Solution and build system updates:

  • Added Deveel.Events.Generators and its XUnit test project to the solution file, with appropriate build configurations and solution folder assignments. [1] [2] [3]

  • Added shared build scripts for samples to centralize dependency compilation and copying, and introduced per-sample scripts that delegate to these core scripts. [1] [2] [3] [4]

Sample dependency management:

  • Updated the OrderService.SimplePublisher sample to reference Deveel.Events dependencies as binaries from a local libs folder, rather than as project references, and documented this workflow. [1] [2]

These changes collectively make it easier to use and understand the new source generator features, improve sample isolation and reproducibility, and streamline the build process for contributors.

References: [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]

@tsutomi tsutomi added this to the v1.6.0 - Code Generation milestone May 3, 2026
@tsutomi tsutomi self-assigned this May 3, 2026
@tsutomi tsutomi added enhancement New feature or request sourcegen labels May 3, 2026
@tsutomi tsutomi linked an issue May 3, 2026 that may be closed by this pull request
Comment on lines +119 to +127
else if (eventJsonSerializationOptionsAttribute is not null && SymbolEqualityComparer.Default.Equals(attrClass, eventJsonSerializationOptionsAttribute))
{
// Constructor arg 0: providerType
if (attr.ConstructorArguments.Length >= 1 &&
attr.ConstructorArguments[0].Value is INamedTypeSymbol t)
{
jsonOptionsProviderTypeName = t.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
}
}
Comment on lines +96 to +99
catch
{
// ignore unresolvable references (e.g. native shims)
}
Comment on lines +78 to +83
foreach (var t in assemblyTypes)
{
var loc = t.Assembly.Location;
if (!string.IsNullOrEmpty(loc))
refs.Add(MetadataReference.CreateFromFile(loc));
}
Comment on lines +155 to +162
foreach (var m in decl.Modifiers)
{
if (m.IsKind(SyntaxKind.PartialKeyword))
{
isPartial = true;
break;
}
}
Comment on lines +172 to +179
foreach (var a in ctx.Attributes)
{
if (a.AttributeClass?.ToDisplayString() == EventAttributeFullName)
{
eventAttr = a;
break;
}
}
Comment on lines +223 to +256
foreach (var attrData in symbol.GetAttributes())
{
if (attrData.AttributeClass?.ToDisplayString() != EventAttributesAttributeFullName)
continue;
if (attrData.ConstructorArguments.Length < 2)
continue;

var attrName = attrData.ConstructorArguments[0].Value as string;
if (attrName is null)
continue;

if (IsEventMetadataReservedName(attrName))
{
collidingNames.Add(attrName);
continue;
}

if (!IsStandardCloudEventAttribute(attrName) && !IsValidCloudEventExtensionName(attrName))
{
invalidExtensionNames.Add(attrName);
continue;
}

var valueConst = attrData.ConstructorArguments[1];
var (valueExpression, attributeType) = GetAttributeValueInfo(valueConst);

extraAttributes.Add(new EventAttributeData
{
Name = attrName,
ValueExpression = valueExpression,
CloudEventAttributeType = attributeType,
IsStandardAttribute = IsStandardCloudEventAttribute(attrName)
});
}
Comment on lines +479 to +481
foreach (var s in StandardCloudEventAttributeNames)
if (string.Equals(s, name, StringComparison.OrdinalIgnoreCase))
return true;
Comment on lines +487 to +489
foreach (var s in EventMetadataReservedNames)
if (string.Equals(s, name, StringComparison.OrdinalIgnoreCase))
return true;
Comment on lines +498 to +502
foreach (char c in name)
{
if ((c < 'a' || c > 'z') && (c < '0' || c > '9'))
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request sourcegen

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CloudEvent Factory Source Generator

1 participant