-
Notifications
You must be signed in to change notification settings - Fork 0
/
StartUp.cs
34 lines (31 loc) · 1.4 KB
/
StartUp.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using Microsoft.Azure.Cosmos;
using Microsoft.Azure.Cosmos.Fluent;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.ApplicationInsights.Extensibility;
using Company.Function;
[assembly: FunctionsStartup(typeof(StartUp))]
namespace Company.Function
{
internal class StartUp : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
// For the Telemetry Initializer to grab the RU charge per call to CosmosDB
/// .NET SDK v2 Approach
builder.Services.AddSingleton<ITelemetryInitializer, DependencyTelemetryInitializer>();
/// .NET SDK v3 Approach
builder.Services.AddSingleton((s) => {
string connectionString = Environment.GetEnvironmentVariable("CosmosDBConnection");
if (string.IsNullOrEmpty(connectionString))
{
throw new ArgumentNullException("Please specify a valid CosmosDBConnection in the appSettings.json file or your Azure Functions Settings.");
}
CosmosClientBuilder configurationBuilder = new CosmosClientBuilder(connectionString);
configurationBuilder.AddCustomHandlers( new DependencyTelemetryRequestHandler() );
return configurationBuilder.Build();
});
}
}
}