@@ -31,20 +31,21 @@ limitations under the License.
3131 options . SupportedCultures = [ invariantCulture ] ;
3232} ) ;
3333
34+ builder . Services . AddDaprClient ( ) ;
35+
3436var app = builder . Build ( ) ;
3537
3638if ( app . Environment . IsDevelopment ( ) ) { app . UseDeveloperExceptionPage ( ) ; }
3739
3840app . UseRequestLocalization ( ) ;
3941
4042// Triggered by Dapr input binding
41- app . MapPost ( "/" + cronBindingName , async ( ) =>
43+ app . MapPost ( "/" + cronBindingName , async ( DaprClient client ) =>
4244{
4345 Console . WriteLine ( "Processing batch.." ) ;
4446
4547 string jsonFile = File . ReadAllText ( "../../../orders.json" ) ;
4648 var ordersArray = JsonSerializer . Deserialize < Orders > ( jsonFile ) ;
47- using var client = new DaprClientBuilder ( ) . Build ( ) ;
4849 foreach ( Order ord in ordersArray ? . orders ?? new Order [ ] { } )
4950 {
5051 var sqlText = $ "insert into orders (orderid, customer, price) values ({ ord . OrderId } , '{ ord . Customer } ', { ord . Price } );";
@@ -65,5 +66,5 @@ limitations under the License.
6566
6667await app . RunAsync ( ) ;
6768
68- public record Order ( [ property: JsonPropertyName ( "orderid" ) ] int OrderId , [ property: JsonPropertyName ( "customer" ) ] string Customer , [ property: JsonPropertyName ( "price" ) ] float Price ) ;
69- public record Orders ( [ property: JsonPropertyName ( "orders" ) ] Order [ ] orders ) ;
69+ public sealed record Order ( [ property: JsonPropertyName ( "orderid" ) ] int OrderId , [ property: JsonPropertyName ( "customer" ) ] string Customer , [ property: JsonPropertyName ( "price" ) ] float Price ) ;
70+ public sealed record Orders ( [ property: JsonPropertyName ( "orders" ) ] Order [ ] orders ) ;
0 commit comments