-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
64 lines (53 loc) · 2.15 KB
/
Program.cs
File metadata and controls
64 lines (53 loc) · 2.15 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Ah_webApiBackend.Data;
using Microsoft.EntityFrameworkCore;
namespace Ah_webApiBackend;
/// <summary>
/// The program.
/// </summary>
public static class Program
{
/// <summary>
/// The main.
/// </summary>
/// <param name="args">
/// The args.
/// </param>
/// <returns>
/// The
/// <see>
/// <cref>void</cref>
/// </see>
/// .
/// </returns>
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args) ??
throw new ArgumentNullException("WebApplication.CreateBuilder(args)");
// Add services to the container.
builder.Services.AddControllers();
// Register CRMDbContext with Dependency Injection
builder.Services.AddDbContext<CrmDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
// Code to troubleshoot the connection string
Console.WriteLine($"Connection String at runtime: {connectionString}");
// Search for the word or character that is causing an issue and throw exception
/* var keyWord = ""; // Takes keyword from the connectionString that is causing an issue
if (connectionString.Contains(keyWord))
throw new Exception($"Invalid keyword {keyWord}detected in connection string: {connectionString}");*/
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "My CRM API v1"));
}
app.UseHttpsRedirection();
app.UseAuthorization();
// Map controllers to routes
app.MapControllers(); // This is crucial to ensure route mapping
app.Run();
}
}