Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions WebApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,39 @@ public class Program
{
public static void Main(string[] args)
{
var communicationContext = CreateAspNetCoreCommunicationContext();
var localWebHost = CreateLocalWebHost();
IHostingEnvironment env = localWebHost.Services.GetService(typeof(IHostingEnvironment)) as IHostingEnvironment;

ServiceRuntime.RegisterServiceAsync("WebAppType", serviceContext => new WebAppService(serviceContext, communicationContext)).GetAwaiter().GetResult();
if (env.IsDevelopment())
{
localWebHost.Run();
}
else
{
var communicationContext = new AspNetCoreCommunicationContext(CreateServiceFabricWebHost());

communicationContext.WebHost.Run();
ServiceRuntime.RegisterServiceAsync("WebAppType", serviceContext => new WebAppService(serviceContext, communicationContext)).GetAwaiter().GetResult();

communicationContext.WebHost.Run();
}
}

private static AspNetCoreCommunicationContext CreateAspNetCoreCommunicationContext()
private static IWebHost CreateLocalWebHost()
{
var webHost = new WebHostBuilder().UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseServiceFabricEndpoint("WebAppTypeEndpoint")
.Build();
return new WebHostBuilder().UseKestrel()
.UseUrls("http://localhost:8001")
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup("WebApp")
.Build();
}

return new AspNetCoreCommunicationContext(webHost);
private static IWebHost CreateServiceFabricWebHost()
{
return new WebHostBuilder().UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseServiceFabricEndpoint("WebAppTypeEndpoint")
.Build();
}
}
}
6 changes: 3 additions & 3 deletions WebApp/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:27904/",
"applicationUrl": "http://localhost:8001/",
"sslPort": 0
}
},
Expand All @@ -15,10 +15,10 @@
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"WebApp": {
"NoFabric": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "http://localhost:5000",
"launchUrl": "http://localhost:8001/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
17 changes: 1 addition & 16 deletions WebApp/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ public Startup(IHostingEnvironment env)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

if (env.IsDevelopment())
{
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();
}

builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
Expand Down Expand Up @@ -58,16 +52,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseExceptionHandler("/Home/Error");

app.UseStaticFiles();

Expand Down
73 changes: 73 additions & 0 deletions WebApp/StartupDevelopment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using WebApp.Data;
using WebApp.Models;
using WebApp.Services;

namespace WebApp
{
public class StartupDevelopment
{
public StartupDevelopment(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder().SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();

builder.AddEnvironmentVariables();
Configuration = builder.Build();
}

public IConfigurationRoot Configuration { get; }

// 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.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();

services.AddMvc();

// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();

app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
app.UseBrowserLink();

app.UseStaticFiles();

app.UseIdentity();

// Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715

app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
3 changes: 2 additions & 1 deletion WebApp/project.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"userSecretsId": "aspnet-WebApp-4b332dff-6daa-4b2c-a482-ddbf5b11741d",

"dependencies": {
Expand All @@ -11,6 +11,7 @@
"version": "1.0.0-preview1-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
Expand Down
9 changes: 9 additions & 0 deletions WebApp/web.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" forwardWindowsAuthToken="false" stdoutLogEnabled="false" />
</system.webServer>
</configuration>