1111
12120 . Install ** Azure development** workload in Visual Studio
1313 * [ 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 )
16162 . Install the ` CommandQuery.AzureFunctions ` package from [ NuGet] ( https://www.nuget.org/packages/CommandQuery.AzureFunctions/ )
1717 * ` PM> ` ` Install-Package CommandQuery.AzureFunctions `
18183 . Create functions
2626
2727![ Add a new project - Azure Functions] ( https://github.com/hlaueriksson/CommandQuery/raw/master/vs-new-project-azure-functions-1.png )
2828
29+ ![ Create a new Azure Functions Application] ( https://github.com/hlaueriksson/CommandQuery/raw/master/vs-new-project-azure-functions-2.png )
30+
2931Choose:
3032
31- * .NET 6 Isolated
33+ * .NET 6.0 Isolated (Long Term Support)
3234* Http trigger
3335
34- ![ Create a new Azure Functions Application] ( https://github.com/hlaueriksson/CommandQuery/raw/master/vs-new-project-azure-functions-2.png )
35-
3636## Commands
3737
3838``` cs
39- using System .Threading .Tasks ;
4039using CommandQuery .AzureFunctions ;
4140using Microsoft .Azure .Functions .Worker ;
4241using Microsoft .Azure .Functions .Worker .Http ;
@@ -57,7 +56,7 @@ namespace CommandQuery.Sample.AzureFunctions.V6
5756
5857 [Function (" Command" )]
5958 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 );
6160 }
6261}
6362```
@@ -75,7 +74,6 @@ Commands with result:
7574## Queries
7675
7776``` cs
78- using System .Threading .Tasks ;
7977using CommandQuery .AzureFunctions ;
8078using Microsoft .Azure .Functions .Worker ;
8179using Microsoft .Azure .Functions .Worker .Http ;
@@ -96,7 +94,7 @@ namespace CommandQuery.Sample.AzureFunctions.V6
9694
9795 [Function (" Query" )]
9896 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 );
10098 }
10199}
102100```
@@ -113,7 +111,7 @@ namespace CommandQuery.Sample.AzureFunctions.V6
113111Configuration in ` Program.cs ` :
114112
115113``` cs
116- using System . Text . Json ;
114+ using CommandQuery ;
117115using CommandQuery .AzureFunctions ;
118116using CommandQuery .Sample .Contracts .Commands ;
119117using CommandQuery .Sample .Contracts .Queries ;
@@ -123,37 +121,31 @@ using CommandQuery.Sample.Handlers.Queries;
123121using Microsoft .Extensions .DependencyInjection ;
124122using Microsoft .Extensions .Hosting ;
125123
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 ();
136128
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 ();
140132
141- host .Run ();
142- }
133+ host .Run ();
143134
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));
148141
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 )
152145
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 >();
157149 }
158150}
159151```
@@ -302,7 +294,5 @@ namespace CommandQuery.Sample.AzureFunctions.V6.Tests
302294
303295## Samples
304296
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 )
307297* [ CommandQuery.Sample.AzureFunctions.V6] ( https://github.com/hlaueriksson/CommandQuery/tree/master/samples/CommandQuery.Sample.AzureFunctions.V6 )
308298* [ CommandQuery.Sample.AzureFunctions.V6.Tests] ( https://github.com/hlaueriksson/CommandQuery/tree/master/samples/CommandQuery.Sample.AzureFunctions.V6.Tests )
0 commit comments