|
15 | 15 | using Intent.Modules.Common.Templates; |
16 | 16 | using Intent.Modules.Constants; |
17 | 17 | using Intent.Modules.Eventing.Contracts.Templates; |
| 18 | +using Intent.Modules.Integration.IaC.Shared.AwsSqs; |
18 | 19 | using Intent.RoslynWeaver.Attributes; |
19 | 20 | using Intent.Templates; |
20 | 21 |
|
@@ -83,22 +84,53 @@ public SqsConfigurationTemplate(IOutputTarget outputTarget, object model = null) |
83 | 84 | method.AddStatement($"services.AddSingleton<{this.GetTypeName(SqsMessageDispatcherTemplate.TemplateId)}>();"); |
84 | 85 | method.AddStatement($"services.AddSingleton<{this.GetTypeName(SqsMessageDispatcherInterfaceTemplate.TemplateId)}, {this.GetTypeName(SqsMessageDispatcherTemplate.TemplateId)}>(sp => sp.GetRequiredService<{this.GetTypeName(SqsMessageDispatcherTemplate.TemplateId)}>());"); |
85 | 86 |
|
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 | + } |
94 | 106 |
|
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) |
98 | 112 | { |
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 | + } |
102 | 134 |
|
103 | 135 | method.AddStatement("return services;", stmt => stmt.SeparatedFromPrevious()); |
104 | 136 | }); |
|
0 commit comments