11
11
12
12
0 . Install ** Azure development** workload in Visual Studio
13
13
* [ Prerequisites] ( https://docs.microsoft.com/en-us/azure/azure-functions/functions-develop-vs?tabs=in-process#prerequisites )
14
- 1 . Create a new ** Azure Functions** project
15
- * [ Tutorial] ( https://docs .microsoft.com/en-us/azure/azure-functions/functions-create-your-first-function-visual-studio )
14
+ 1 . Create a new ** Azure Functions** ( _ isolated worker process _ ) project
15
+ * [ Tutorial] ( https://learn .microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide )
16
16
2 . Install the ` CommandQuery.AzureFunctions ` package from [ NuGet] ( https://www.nuget.org/packages/CommandQuery.AzureFunctions/ )
17
17
* ` PM> ` ` Install-Package CommandQuery.AzureFunctions `
18
18
3 . Create functions
26
26
27
27
![ Add a new project - Azure Functions] ( https://github.com/hlaueriksson/CommandQuery/raw/master/vs-new-project-azure-functions-1.png )
28
28
29
+ ![ Create a new Azure Functions Application] ( https://github.com/hlaueriksson/CommandQuery/raw/master/vs-new-project-azure-functions-2.png )
30
+
29
31
Choose:
30
32
31
- * .NET 6 Isolated
33
+ * .NET 6.0 Isolated (Long Term Support)
32
34
* Http trigger
33
35
34
- ![ Create a new Azure Functions Application] ( https://github.com/hlaueriksson/CommandQuery/raw/master/vs-new-project-azure-functions-2.png )
35
-
36
36
## Commands
37
37
38
38
``` cs
39
- using System .Threading .Tasks ;
40
39
using CommandQuery .AzureFunctions ;
41
40
using Microsoft .Azure .Functions .Worker ;
42
41
using Microsoft .Azure .Functions .Worker .Http ;
@@ -57,7 +56,7 @@ namespace CommandQuery.Sample.AzureFunctions.V6
57
56
58
57
[Function (" Command" )]
59
58
public async Task <HttpResponseData > Run ([HttpTrigger (AuthorizationLevel .Anonymous , " post" , Route = " command/{commandName}" )] HttpRequestData req , FunctionContext executionContext , string commandName ) =>
60
- await _commandFunction .HandleAsync (commandName , req , _logger );
59
+ await _commandFunction .HandleAsync (commandName , req , _logger , executionContext . CancellationToken );
61
60
}
62
61
}
63
62
```
@@ -75,7 +74,6 @@ Commands with result:
75
74
## Queries
76
75
77
76
``` cs
78
- using System .Threading .Tasks ;
79
77
using CommandQuery .AzureFunctions ;
80
78
using Microsoft .Azure .Functions .Worker ;
81
79
using Microsoft .Azure .Functions .Worker .Http ;
@@ -96,7 +94,7 @@ namespace CommandQuery.Sample.AzureFunctions.V6
96
94
97
95
[Function (" Query" )]
98
96
public async Task <HttpResponseData > Run ([HttpTrigger (AuthorizationLevel .Anonymous , " get" , " post" , Route = " query/{queryName}" )] HttpRequestData req , FunctionContext executionContext , string queryName ) =>
99
- await _queryFunction .HandleAsync (queryName , req , _logger );
97
+ await _queryFunction .HandleAsync (queryName , req , _logger , executionContext . CancellationToken );
100
98
}
101
99
}
102
100
```
@@ -113,7 +111,7 @@ namespace CommandQuery.Sample.AzureFunctions.V6
113
111
Configuration in ` Program.cs ` :
114
112
115
113
``` cs
116
- using System . Text . Json ;
114
+ using CommandQuery ;
117
115
using CommandQuery .AzureFunctions ;
118
116
using CommandQuery .Sample .Contracts .Commands ;
119
117
using CommandQuery .Sample .Contracts .Queries ;
@@ -123,37 +121,31 @@ using CommandQuery.Sample.Handlers.Queries;
123
121
using Microsoft .Extensions .DependencyInjection ;
124
122
using Microsoft .Extensions .Hosting ;
125
123
126
- namespace CommandQuery .Sample .AzureFunctions .V6
127
- {
128
- public class Program
129
- {
130
- public static void Main ()
131
- {
132
- var host = new HostBuilder ()
133
- .ConfigureFunctionsWorkerDefaults ()
134
- .ConfigureServices (ConfigureServices )
135
- .Build ();
124
+ var host = new HostBuilder ()
125
+ .ConfigureFunctionsWorkerDefaults ()
126
+ .ConfigureServices (ConfigureServices )
127
+ .Build ();
136
128
137
- // Validation
138
- host .Services .GetService <ICommandProcessor >().AssertConfigurationIsValid ();
139
- host .Services .GetService <IQueryProcessor >().AssertConfigurationIsValid ();
129
+ // Validation
130
+ host .Services .GetService <ICommandProcessor >()! .AssertConfigurationIsValid ();
131
+ host .Services .GetService <IQueryProcessor >()! .AssertConfigurationIsValid ();
140
132
141
- host .Run ();
142
- }
133
+ host .Run ();
143
134
144
- public static void ConfigureServices (IServiceCollection services )
145
- {
146
- services
147
- // .AddSingleton(new JsonSerializerOptions(JsonSerializerDefaults.Web));
135
+ public static partial class Program
136
+ {
137
+ public static void ConfigureServices (IServiceCollection services )
138
+ {
139
+ services
140
+ // .AddSingleton(new JsonSerializerOptions(JsonSerializerDefaults.Web));
148
141
149
- // Add commands and queries
150
- .AddCommandFunction (typeof (FooCommandHandler ).Assembly , typeof (FooCommand ).Assembly )
151
- .AddQueryFunction (typeof (BarQueryHandler ).Assembly , typeof (BarQuery ).Assembly )
142
+ // Add commands and queries
143
+ .AddCommandFunction (typeof (FooCommandHandler ).Assembly , typeof (FooCommand ).Assembly )
144
+ .AddQueryFunction (typeof (BarQueryHandler ).Assembly , typeof (BarQuery ).Assembly )
152
145
153
- // Add handler dependencies
154
- .AddTransient <IDateTimeProxy , DateTimeProxy >()
155
- .AddTransient <ICultureService , CultureService >();
156
- }
146
+ // Add handler dependencies
147
+ .AddTransient <IDateTimeProxy , DateTimeProxy >()
148
+ .AddTransient <ICultureService , CultureService >();
157
149
}
158
150
}
159
151
```
@@ -302,7 +294,5 @@ namespace CommandQuery.Sample.AzureFunctions.V6.Tests
302
294
303
295
## Samples
304
296
305
- * [ CommandQuery.Sample.AzureFunctions.V3] ( https://github.com/hlaueriksson/CommandQuery/tree/master/samples/CommandQuery.Sample.AzureFunctions.V3 )
306
- * [ CommandQuery.Sample.AzureFunctions.V3.Tests] ( https://github.com/hlaueriksson/CommandQuery/tree/master/samples/CommandQuery.Sample.AzureFunctions.V3.Tests )
307
297
* [ CommandQuery.Sample.AzureFunctions.V6] ( https://github.com/hlaueriksson/CommandQuery/tree/master/samples/CommandQuery.Sample.AzureFunctions.V6 )
308
298
* [ CommandQuery.Sample.AzureFunctions.V6.Tests] ( https://github.com/hlaueriksson/CommandQuery/tree/master/samples/CommandQuery.Sample.AzureFunctions.V6.Tests )
0 commit comments