Last active
June 19, 2017 21:42
-
-
Save mishuagopian/04aa65885cb126016c1009d350bec01f to your computer and use it in GitHub Desktop.
Net Core Training - PostgreSQL configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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;" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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