-
Notifications
You must be signed in to change notification settings - Fork 0
/
Startup.cs
71 lines (65 loc) · 2.45 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AspNetBlog.Models;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Data.Entity;
using Microsoft.Framework.Configuration;
using Microsoft.Dnx.Runtime;
using AspNetBlog.Models.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
namespace AspNetBlog
{
public class Startup
{
public IConfigurationRoot config { get; set; }
public Startup(IApplicationEnvironment env)
{
config = new ConfigurationBuilder(env.ApplicationBasePath)
.AddEnvironmentVariables()
.AddJsonFile("config.json")
.AddJsonFile("config.dev.json", true)
.AddUserSecrets()
.Build();
}
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped<AspNetBlog.Models.BlogDataContext>();
services.AddScoped<AspNetBlog.Models.Identity.IdentityDataContext>();
services.AddTransient<AspNetBlog.Models.FormattingService>();
var connectPostgres = "Host=localhost;Username=postgres;Password=root;Database=asp_net_blog";
var identityConnectionString = "Host=localhost;Username=postgres;Password=root;Database=asp_net_blog_identity";
services.AddEntityFramework()
.AddNpgsql()
.AddDbContext<BlogDataContext>(options =>
options.UseNpgsql(connectPostgres))
.AddDbContext<IdentityDataContext>(dbConfig =>
dbConfig.UseNpgsql(identityConnectionString));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<IdentityDataContext>();
services.AddMvc();
}
public void Configure(IApplicationBuilder app)
{
app.UseIdentity();
var password = config["password"];
if (config["debug"] == "true")
{
app.UseErrorPage();
app.UseRuntimeInfoPage();
}
else
{
app.UseErrorHandler("/home/error");
}
app.UseMvc(routes =>
routes.MapRoute("Defoult",
"{controller=Home}/{action=Index}/{id?}"));
app.UseStaticFiles();
}
}
}