Skip to content

Instantly share code, notes, and snippets.

View gmartinezsan's full-sized avatar

Gabriela Martinez gmartinezsan

View GitHub Profile
using System;
using BooksWebApi.Data;
using BooksWebApi.Entities;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace BooksWebApi
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=HOST\\SQLEXPRESS;Initial Catalog=DbBooksCat;User ID=user;Password=YourPaasowrd;",
"AzureConnection": "Server=tcp:sqlserver.database.windows.net,1433;Initial Catalog=booksdb;Persist Security Info=False;User ID=admin;Password=YourPassword;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
},
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Debug"
if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
{
services.AddDbContext<BooksCatalogDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
}
else
{
services.AddDbContext<BooksCatalogDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("AzureConnection")));
}
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Error");
}
app.UseAuthentication();