Skip to content

Commit e57fed7

Browse files
Copilotdandrejvv
andcommitted
Complete Phase 3-4: Factory extension registered, SqsConfiguration uses IntegrationManager
Co-authored-by: dandrejvv <[email protected]>
1 parent 74cfe24 commit e57fed7

File tree

2 files changed

+49
-15
lines changed

2 files changed

+49
-15
lines changed

Modules/Intent.Modules.Aws.Sqs/Intent.Aws.Sqs.imodspec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@
5858
</template>
5959
</templates>
6060
<decorators></decorators>
61-
<factoryExtensions></factoryExtensions>
61+
<factoryExtensions>
62+
<factoryExtension id="Intent.Aws.Sqs.MetadataLoaderExtension" externalReference="9a8b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d" />
63+
</factoryExtensions>
6264
<moduleSettings></moduleSettings>
6365
<dependencies>
6466
<dependency id="Intent.Common" version="3.9.0" />

Modules/Intent.Modules.Aws.Sqs/Templates/SqsConfiguration/SqsConfigurationTemplatePartial.cs

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Intent.Modules.Common.Templates;
1616
using Intent.Modules.Constants;
1717
using Intent.Modules.Eventing.Contracts.Templates;
18+
using Intent.Modules.Integration.IaC.Shared.AwsSqs;
1819
using Intent.RoslynWeaver.Attributes;
1920
using Intent.Templates;
2021

@@ -83,22 +84,53 @@ public SqsConfigurationTemplate(IOutputTarget outputTarget, object model = null)
8384
method.AddStatement($"services.AddSingleton<{this.GetTypeName(SqsMessageDispatcherTemplate.TemplateId)}>();");
8485
method.AddStatement($"services.AddSingleton<{this.GetTypeName(SqsMessageDispatcherInterfaceTemplate.TemplateId)}, {this.GetTypeName(SqsMessageDispatcherTemplate.TemplateId)}>(sp => sp.GetRequiredService<{this.GetTypeName(SqsMessageDispatcherTemplate.TemplateId)}>());");
8586

86-
// Configure publisher options (metadata-driven - placeholder for now)
87-
method.AddStatement("");
88-
method.AddInvocationStatement($"services.Configure<{this.GetTypeName(SqsPublisherOptionsTemplate.TemplateId)}>", inv => inv
89-
.AddArgument(new CSharpLambdaBlock("options"), arg =>
90-
{
91-
arg.AddStatement("// Publisher options will be configured here based on metadata");
92-
arg.AddStatement("// Example: options.AddQueue<YourMessageType>(configuration[\"Sqs:Queues:YourMessageType:QueueUrl\"]!);");
93-
}));
87+
// Get metadata from IntegrationManager
88+
var publishers = IntegrationManager.Instance.GetAggregatedPublishedSqsItems(ExecutionContext.GetApplicationConfig().Id);
89+
var subscriptions = IntegrationManager.Instance.GetAggregatedSqsSubscriptions(ExecutionContext.GetApplicationConfig().Id);
90+
91+
// Configure publisher options (metadata-driven)
92+
if (publishers.Any())
93+
{
94+
method.AddStatement("");
95+
method.AddInvocationStatement($"services.Configure<{this.GetTypeName(SqsPublisherOptionsTemplate.TemplateId)}>", inv => inv
96+
.AddArgument(new CSharpLambdaBlock("options"), arg =>
97+
{
98+
foreach (var publisher in publishers)
99+
{
100+
var messageType = publisher.GetModelTypeName(this);
101+
var configKey = $"\"{publisher.QueueConfigurationName}:QueueUrl\"";
102+
arg.AddStatement($"options.AddQueue<{messageType}>(configuration[{configKey}]!);");
103+
}
104+
}));
105+
}
94106

95-
// Configure subscription options (metadata-driven - placeholder for now)
96-
method.AddInvocationStatement($"services.Configure<{this.GetTypeName(SqsSubscriptionOptionsTemplate.TemplateId)}>", inv => inv
97-
.AddArgument(new CSharpLambdaBlock("options"), arg =>
107+
// Register event handlers (metadata-driven)
108+
if (subscriptions.Any())
109+
{
110+
method.AddStatement("");
111+
foreach (var subscription in subscriptions)
98112
{
99-
arg.AddStatement("// Subscription options will be configured here based on metadata");
100-
arg.AddStatement("// Example: options.Add<YourMessageType, YourMessageHandler>();");
101-
}));
113+
var handlerType = subscription.SubscriptionItem.GetSubscriberTypeName(this);
114+
var handlerImplementation = this.GetTypeName("Intent.Eventing.Contracts.IntegrationEventHandler", subscription.EventHandlerModel);
115+
method.AddStatement($"services.AddTransient<{handlerType}, {handlerImplementation}>();");
116+
}
117+
}
118+
119+
// Configure subscription options (metadata-driven)
120+
if (subscriptions.Any())
121+
{
122+
method.AddStatement("");
123+
method.AddInvocationStatement($"services.Configure<{this.GetTypeName(SqsSubscriptionOptionsTemplate.TemplateId)}>", inv => inv
124+
.AddArgument(new CSharpLambdaBlock("options"), arg =>
125+
{
126+
foreach (var subscription in subscriptions)
127+
{
128+
var messageType = subscription.SubscriptionItem.GetModelTypeName(this);
129+
var handlerType = subscription.SubscriptionItem.GetSubscriberTypeName(this);
130+
arg.AddStatement($"options.Add<{messageType}, {handlerType}>();");
131+
}
132+
}));
133+
}
102134

103135
method.AddStatement("return services;", stmt => stmt.SeparatedFromPrevious());
104136
});

0 commit comments

Comments
 (0)