Skip to content

Instantly share code, notes, and snippets.

@atrauzzi
Last active September 2, 2017 21:44
Show Gist options
  • Save atrauzzi/5a00adb495c293260ec5 to your computer and use it in GitHub Desktop.
Save atrauzzi/5a00adb495c293260ec5 to your computer and use it in GitHub Desktop.
Using Postgres on Docker with EF7 and ASP.NET 5
namespace App {
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Data.Entity;
public class ApplicationDbContext : IdentityDbContext {
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
// ToDo: Obtain these values from the environment, rather than hard-coding them.
optionsBuilder.UseNpgsql("Server=aspnet;Database=aspnet;Username=aspnet;Password=aspnet;");
}
}
}
database:
container_name: database
image: postgres
environment:
POSTGRES_USER: aspnet
POSTGRES_PASSWORD: aspnet
POSTGRES_DB: aspnet
ports:
- "5432:5432"
"dependencies": {
"EntityFramework7.Npgsql": "3.1.0-rc1-3",
"EntityFramework.Commands": "7.0.0-rc1-final"
},
"commands": {
"ef": "EntityFramework.Commands",
},
public void ConfigureServices(IServiceCollection services) {
services
.AddEntityFramework()
.AddNpgsql()
;
services
.AddIdentity<User, Role>()
.AddEntityFrameworkStores<ApplicationDbContext>()
;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment