@@ -51,29 +51,30 @@ public SqsConfigurationTemplate(IOutputTarget outputTarget, object? model = null
5151
5252 // Register SQS client (with LocalStack support)
5353 method . AddStatement ( """var serviceUrl = configuration["AWS:ServiceURL"];""" ) ;
54- var ifStmt = method . AddIfStatement ( "!string.IsNullOrEmpty(serviceUrl)" ) ;
55- ifStmt . AddStatement ( "// LocalStack or custom endpoint" ) ;
56- ifStmt . AddInvocationStatement ( "services.AddSingleton<IAmazonSQS>" , inv => inv
57- . AddArgument ( new CSharpLambdaBlock ( "sp" ) , arg =>
58- {
59- arg . AddStatement ( """
60- var sqsConfig = new AmazonSQSConfig
61- {
62- ServiceURL = serviceUrl,
63- AuthenticationRegion = configuration["AWS:Region"] ?? "us-east-1"
64- };
65- """ ) ;
66- arg . AddStatement ( """
67- return new AmazonSQSClient(
68- new BasicAWSCredentials("test", "test"),
69- sqsConfig
70- );
71- """ ) ;
72- } ) ) ;
54+ method . AddIfStatement ( "!string.IsNullOrEmpty(serviceUrl)" , ifStmt =>
55+ {
56+ ifStmt . AddStatement ( "// LocalStack or custom endpoint" ) ;
57+ ifStmt . AddInvocationStatement ( "services.AddSingleton<IAmazonSQS>" , inv => inv
58+ . AddArgument ( new CSharpLambdaBlock ( "sp" ) , arg =>
59+ {
60+ arg . AddStatement ( new CSharpAssignmentStatement (
61+ new CSharpVariableDeclaration ( "sqsConfig" ) ,
62+ new CSharpObjectInitializerBlock ( "new AmazonSQSConfig" )
63+ . AddInitStatement ( "ServiceURL" , "serviceUrl" )
64+ . AddInitStatement ( "AuthenticationRegion" , @"configuration[""AWS:Region""] ?? ""us-east-1""" ) )
65+ . WithSemicolon ( ) ) ;
66+ arg . AddReturn ( new CSharpInvocationStatement ( "new AmazonSQSClient" )
67+ . AddArgument ( @"new BasicAWSCredentials(""test"", ""test"")" )
68+ . AddArgument ( @"sqsConfig" )
69+ . WithoutSemicolon ( ) ) ;
70+ } ) ) ;
71+ } ) ;
7372
74- var elseStmt = ifStmt . AddElseStatement ( ) ;
75- elseStmt . AddStatement ( "// Production AWS" ) ;
76- elseStmt . AddStatement ( "services.AddAWSService<IAmazonSQS>();" ) ;
73+ method . AddElseStatement ( elseStmt =>
74+ {
75+ elseStmt . AddStatement ( "// Production AWS" ) ;
76+ elseStmt . AddStatement ( "services.AddAWSService<IAmazonSQS>();" ) ;
77+ } ) ;
7778
7879 // Register event bus
7980 method . AddStatement ( $ "services.AddScoped<{ this . GetEventBusInterfaceName ( ) } , { this . GetTypeName ( SqsEventBusTemplate . TemplateId ) } >();", stmt => stmt . SeparatedFromPrevious ( ) ) ;
0 commit comments