Skip to content

How to run a project

Tymofii edited this page Mar 14, 2024 · 6 revisions
  • Visual Studio

Make sure you have the necessary libraries and environments for execution. What is the project built on?

In my project, 'AzureSecrets' is often used for storing keys. Below are the places where you need to either delete code or insert your token for the project to function correctly.

remove this code if you have not configured Azure. 'Program.cs'

//Azure
var keyVaultEndpoint = new Uri(Environment.GetEnvironmentVariable("VaultUri"));
builder.Configuration.AddAzureKeyVault(keyVaultEndpoint, new DefaultAzureCredential());

Place your SendGrid Apikey in ApiKey and the sender's email address in SenderEmail. 'Program.cs'

//Set SendGridEmailSenderOption and Service
builder.Services.AddTransient<IEmailSender, SendGridEmailService>();
builder.Services.Configure<Domain.Models.SendGridEmailSenderOption>(opt =>
{
    opt.ApiKey = builder.Configuration.GetValue<string>("SGKey");
    opt.SenderEmail = builder.Configuration.GetValue<string>("SGKeyEmail");
    opt.SenderName = "Tima";
});

Place your token in 'var token' LocationController. The token can be obtained from here ipinfo.io.

[HttpGet(nameof(GetUserLocationViaIP))]
public async Task<IActionResult> GetUserLocationViaIP()
{
    var token = _configuration.GetValue<string>("IpInfoToken");
    //...
}

Don't forget to select your database in "ConfigurationBLL"

public static class ConfigrationBLL
{
    public static void Configure(this IServiceCollection services, IConfiguration configuration)
    {
        // Database Configuration
        var local = configuration.GetConnectionString("local");//appsettings
        //var realDatabse = configuration.GetValue<string>("BeautyBookDatabase");//Azure secret key
        services.AddDbContext<BeautyBookDbContext>(opt => opt.UseSqlServer(local));
        //services.AddDbContext<BeautyBookDbContext>(options => options.UseInMemoryDatabase(nameof(BeautyBookDbContext)));//InMemory
  }
}
Clone this wiki locally