forked from pnp/copilot-pro-dev-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartup.cs
More file actions
49 lines (40 loc) · 2.01 KB
/
Copy pathStartup.cs
File metadata and controls
49 lines (40 loc) · 2.01 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Trey.Research.Declarative.Agent.DbSetup;
using Trey.Research.Declarative.Agent.Services;
using System;
using Trey.Research.Declarative.Agent.Models;
[assembly: FunctionsStartup(typeof(Trey.Research.Declarative.Agent.Startup))]
namespace Trey.Research.Declarative.Agent
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
var configuration = builder.GetContext().Configuration;
var contentRootPath = builder.GetContext().ApplicationRootPath;
if (configuration == null)
{
throw new InvalidOperationException("Configuration is not available.");
}
var storageConnectionString = configuration["AzureWebJobsStorage"];
Utilities.Utility.Initialize(configuration);
if (string.IsNullOrEmpty(storageConnectionString))
{
throw new ArgumentNullException(nameof(storageConnectionString), "Storage connection string cannot be null or empty.");
}
// Pass the content root path to the AzureTableSetup instance
var azureTableSetup = new AzureTableSetup(storageConnectionString);
builder.Services.AddSingleton(azureTableSetup);
// Register your services with the DI container
builder.Services.AddSingleton<ConsultantApiService>();
builder.Services.AddSingleton<IdentityService>();
builder.Services.AddSingleton<ProjectApiService>();
// Register DbService with the configuration and caching option
builder.Services.AddSingleton<DbService<DbEntity>>(provider =>
new DbService<DbEntity>(configuration, okToCacheLocally: true));
// Call the setup method to initialize the tables
azureTableSetup.SetupTablesAndDataAsync().GetAwaiter().GetResult();
}
}
}