@@ -48,20 +48,19 @@ using Microsoft.Extensions.DependencyInjection;
48
48
49
49
[assembly : FunctionsStartup (typeof (MyNamespace .Startup ))]
50
50
51
- namespace MyNamespace
51
+ namespace MyNamespace ;
52
+
53
+ public class Startup : FunctionsStartup
52
54
{
53
- public class Startup : FunctionsStartup
55
+ public override void Configure ( IFunctionsHostBuilder builder )
54
56
{
55
- public override void Configure (IFunctionsHostBuilder builder )
56
- {
57
- builder .Services .AddHttpClient ();
57
+ builder .Services .AddHttpClient ();
58
58
59
- builder .Services .AddSingleton <IMyService >((s ) => {
60
- return new MyService ();
61
- });
59
+ builder .Services .AddSingleton <IMyService >((s ) => {
60
+ return new MyService ();
61
+ });
62
62
63
- builder .Services .AddSingleton <ILoggerProvider , MyLoggerProvider >();
64
- }
63
+ builder .Services .AddSingleton <ILoggerProvider , MyLoggerProvider >();
65
64
}
66
65
}
67
66
```
@@ -91,29 +90,28 @@ using Microsoft.Extensions.Logging;
91
90
using System .Net .Http ;
92
91
using System .Threading .Tasks ;
93
92
94
- namespace MyNamespace
93
+ namespace MyNamespace ;
94
+
95
+ public class MyHttpTrigger
95
96
{
96
- public class MyHttpTrigger
97
- {
98
- private readonly HttpClient _client ;
99
- private readonly IMyService _service ;
97
+ private readonly HttpClient _client ;
98
+ private readonly IMyService _service ;
100
99
101
- public MyHttpTrigger (IHttpClientFactory httpClientFactory , IMyService service )
102
- {
103
- this ._client = httpClientFactory .CreateClient ();
104
- this ._service = service ;
105
- }
100
+ public MyHttpTrigger (IHttpClientFactory httpClientFactory , IMyService service )
101
+ {
102
+ this ._client = httpClientFactory .CreateClient ();
103
+ this ._service = service ;
104
+ }
106
105
107
- [FunctionName (" MyHttpTrigger" )]
108
- public async Task <IActionResult > Run (
109
- [HttpTrigger (AuthorizationLevel .Function , " get" , " post" , Route = null )] HttpRequest req ,
110
- ILogger log )
111
- {
112
- var response = await _client .GetAsync (" https://microsoft.com" );
113
- var message = _service .GetMessage ();
106
+ [FunctionName (" MyHttpTrigger" )]
107
+ public async Task <IActionResult > Run (
108
+ [HttpTrigger (AuthorizationLevel .Function , " get" , " post" , Route = null )] HttpRequest req ,
109
+ ILogger log )
110
+ {
111
+ var response = await _client .GetAsync (" https://microsoft.com" );
112
+ var message = _service .GetMessage ();
114
113
115
- return new OkObjectResult (" Response from function with injected dependencies." );
116
- }
114
+ return new OkObjectResult (" Response from function with injected dependencies." );
117
115
}
118
116
}
119
117
```
@@ -147,25 +145,24 @@ The host injects `ILogger<T>` and `ILoggerFactory` services into constructors.
147
145
The following example demonstrates how to add an ` ILogger<HttpTrigger> ` with logs that are exposed to the host.
148
146
149
147
``` csharp
150
- namespace MyNamespace
148
+ namespace MyNamespace ;
149
+
150
+ public class HttpTrigger
151
151
{
152
- public class HttpTrigger
153
- {
154
- private readonly ILogger <HttpTrigger > _log ;
152
+ private readonly ILogger <HttpTrigger > _log ;
155
153
156
- public HttpTrigger (ILogger <HttpTrigger > log )
157
- {
158
- _log = log ;
159
- }
154
+ public HttpTrigger (ILogger <HttpTrigger > log )
155
+ {
156
+ _log = log ;
157
+ }
160
158
161
- [FunctionName (" HttpTrigger" )]
162
- public async Task <IActionResult > Run (
163
- [HttpTrigger (AuthorizationLevel .Anonymous , " get" , " post" , Route = null )] HttpRequest req )
164
- {
165
- _log .LogInformation (" C# HTTP trigger function processed a request." );
159
+ [FunctionName (" HttpTrigger" )]
160
+ public async Task <IActionResult > Run (
161
+ [HttpTrigger (AuthorizationLevel .Anonymous , " get" , " post" , Route = null )] HttpRequest req )
162
+ {
163
+ _log .LogInformation (" C# HTTP trigger function processed a request." );
166
164
167
- // ...
168
- }
165
+ // ...
169
166
}
170
167
```
171
168
@@ -293,23 +290,22 @@ using Microsoft.Extensions.DependencyInjection;
293
290
294
291
[assembly : FunctionsStartup (typeof (MyNamespace .Startup ))]
295
292
296
- namespace MyNamespace
293
+ namespace MyNamespace ;
294
+
295
+ public class Startup : FunctionsStartup
297
296
{
298
- public class Startup : FunctionsStartup
297
+ public override void ConfigureAppConfiguration (IFunctionsConfigurationBuilder builder )
298
+ {
299
+ FunctionsHostBuilderContext context = builder .GetContext ();
300
+
301
+ builder .ConfigurationBuilder
302
+ .AddJsonFile (Path .Combine (context .ApplicationRootPath , " appsettings.json" ), optional : true , reloadOnChange : false )
303
+ .AddJsonFile (Path .Combine (context .ApplicationRootPath , $" appsettings.{context .EnvironmentName }.json" ), optional : true , reloadOnChange : false )
304
+ .AddEnvironmentVariables ();
305
+ }
306
+
307
+ public override void Configure (IFunctionsHostBuilder builder )
299
308
{
300
- public override void ConfigureAppConfiguration (IFunctionsConfigurationBuilder builder )
301
- {
302
- FunctionsHostBuilderContext context = builder .GetContext ();
303
-
304
- builder .ConfigurationBuilder
305
- .AddJsonFile (Path .Combine (context .ApplicationRootPath , " appsettings.json" ), optional : true , reloadOnChange : false )
306
- .AddJsonFile (Path .Combine (context .ApplicationRootPath , $" appsettings.{context .EnvironmentName }.json" ), optional : true , reloadOnChange : false )
307
- .AddEnvironmentVariables ();
308
- }
309
-
310
- public override void Configure (IFunctionsHostBuilder builder )
311
- {
312
- }
313
309
}
314
310
}
315
311
```
0 commit comments