Skip to content

Instantly share code, notes, and snippets.

@mishuagopian
Last active June 19, 2017 21:42
Show Gist options
  • Save mishuagopian/04aa65885cb126016c1009d350bec01f to your computer and use it in GitHub Desktop.
Save mishuagopian/04aa65885cb126016c1009d350bec01f to your computer and use it in GitHub Desktop.
Net Core Training - PostgreSQL configuration
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
},
"DbContextSettings" :{
"DbConnectionString" : "User ID=postgres;Password=postgres;Host=localhost;Port=5432;Database=test_asp;Pooling=true;Timeout=1024;CommandTimeout=1024;"
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
using MvcMovie.Models;
namespace mvc
{
public class Startup
{
// ...
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
var connectionString = Configuration["DbContextSettings:DbConnectionString"];
services.AddDbContext<DataBaseContext>(options => options.UseNpgsql(connectionString));
services.AddScoped<DataBaseContext>();
}
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment