1+ // Copyright (c) Microsoft Corporation.
2+ // Licensed under the MIT License.
3+
4+ using System . Text . Json . Serialization ;
5+ using Microsoft . DurableTask . Client ;
6+ using Microsoft . DurableTask . Client . AzureManaged ;
7+ using Microsoft . DurableTask . ScheduledTasks ;
8+ using Microsoft . DurableTask . Worker ;
9+ using Microsoft . DurableTask . Worker . AzureManaged ;
10+ using ScheduleWebApp . Orchestrations ;
11+
12+ WebApplicationBuilder builder = WebApplication . CreateBuilder ( args ) ;
13+
14+ string connectionString = builder . Configuration [ "DURABLE_TASK_SCHEDULER_CONNECTION_STRING" ]
15+ ?? throw new InvalidOperationException ( "Missing required configuration 'DURABLE_TASK_SCHEDULER_CONNECTION_STRING'" ) ;
16+
17+ // Add all the generated orchestrations and activities automatically
18+ builder . Services . AddDurableTaskWorker ( builder =>
19+ {
20+ builder . AddTasks ( r =>
21+ {
22+ // Add your orchestrators and activities here
23+ r . AddOrchestrator < CacheClearingOrchestrator > ( ) ;
24+ } ) ;
25+ builder . UseDurableTaskScheduler ( connectionString ) ;
26+ builder . EnableScheduledTasksSupport ( ) ;
27+ } ) ;
28+
29+ // Register the client, which can be used to start orchestrations
30+ builder . Services . AddDurableTaskClient ( builder =>
31+ {
32+ builder . UseDurableTaskScheduler ( connectionString ) ;
33+ builder . EnableScheduledTasksSupport ( ) ;
34+ } ) ;
35+
36+ // Configure console logging using the simpler, more compact format
37+ builder . Services . AddLogging ( logging =>
38+ {
39+ logging . AddSimpleConsole ( options =>
40+ {
41+ options . SingleLine = true ;
42+ options . UseUtcTimestamp = true ;
43+ options . TimestampFormat = "yyyy-MM-ddTHH:mm:ss.fffZ " ;
44+ } ) ;
45+ } ) ;
46+
47+ // Configure the HTTP request pipeline
48+ builder . Services . AddControllers ( ) . AddJsonOptions ( options =>
49+ {
50+ options . JsonSerializerOptions . Converters . Add ( new JsonStringEnumConverter ( ) ) ;
51+ options . JsonSerializerOptions . DefaultIgnoreCondition = JsonIgnoreCondition . WhenWritingNull ;
52+ } ) ;
53+
54+ // The actual listen URL can be configured in environment variables named "ASPNETCORE_URLS" or "ASPNETCORE_URLS_HTTPS"
55+ WebApplication app = builder . Build ( ) ;
56+ app . MapControllers ( ) ;
57+ app . Run ( ) ;
0 commit comments