-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multiple providers and dynamic configuration (#76)
* . * cleanup
- Loading branch information
1 parent
23d9b62
commit e3e169e
Showing
31 changed files
with
974 additions
and
12 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Reflection; | ||
|
||
namespace WebOptimizer.Core.Sample2.Lib | ||
{ | ||
public class AssemblyTools | ||
{ | ||
public static Assembly GetCurrentAssembly() | ||
{ | ||
return typeof(AssemblyTools).Assembly; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(function (innerhtml) { | ||
var content = document.getElementById("content"), | ||
div = document.createElement("div"); | ||
|
||
div.innerHTML = innerhtml; | ||
content.appendChild(div); | ||
})('/EmbeddedResourcesScripts/EmbeddedScript1.js loaded'); |
7 changes: 7 additions & 0 deletions
7
sample2/WebOptimizer.Core.Sample2.Lib/Scripts/EmbeddedScript2.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(function (innerhtml) { | ||
var content = document.getElementById("content"), | ||
div = document.createElement("div"); | ||
|
||
div.innerHTML = innerhtml; | ||
content.appendChild(div); | ||
})('/EmbeddedResourcesScripts/Scripts/EmbeddedScript2.js loaded'); |
18 changes: 18 additions & 0 deletions
18
sample2/WebOptimizer.Core.Sample2.Lib/WebOptimizer.Core.Sample2.Lib.csproj
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
|
||
<ItemGroup> | ||
<None Remove="Scripts\EmbeddedScript2.js" /> | ||
<None Remove="EmbeddedScript1.js" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<EmbeddedResource Include="Scripts\EmbeddedScript2.js" /> | ||
<EmbeddedResource Include="EmbeddedScript1.js" /> | ||
</ItemGroup> | ||
|
||
</Project> |
20 changes: 20 additions & 0 deletions
20
sample2/WebOptimizer.Core.Sample2/Controllers/HomeController.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Diagnostics; | ||
using Microsoft.AspNetCore.Mvc; | ||
using WebOptimizer.Core.Sample2.Models; | ||
|
||
namespace WebOptimizer.Core.Sample2.Controllers | ||
{ | ||
public class HomeController : Controller | ||
{ | ||
public IActionResult Index() | ||
{ | ||
return View(); | ||
} | ||
|
||
|
||
public IActionResult Error() | ||
{ | ||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
sample2/WebOptimizer.Core.Sample2/Models/ErrorViewModel.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace WebOptimizer.Core.Sample2.Models | ||
{ | ||
public class ErrorViewModel | ||
{ | ||
public string RequestId { get; set; } | ||
|
||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace WebOptimizer.Core.Sample2 | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
BuildWebHost(args).Run(); | ||
} | ||
|
||
public static IWebHost BuildWebHost(string[] args) => | ||
WebHost.CreateDefaultBuilder(args) | ||
.UseStartup<Startup>() | ||
.Build(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
sample2/WebOptimizer.Core.Sample2/Properties/launchSettings.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:61838/", | ||
"sslPort": 0 | ||
} | ||
}, | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"WebOptimizer.Core.Sample2": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "http://localhost:62609/" | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(function (innerhtml) { | ||
var content = document.getElementById("content"), | ||
div = document.createElement("div"); | ||
|
||
div.innerHTML = innerhtml; | ||
content.appendChild(div); | ||
})('/Scripts1/Script1.js loaded'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(function (innerhtml) { | ||
var content = document.getElementById("content"), | ||
div = document.createElement("div"); | ||
|
||
div.innerHTML = innerhtml; | ||
content.appendChild(div); | ||
})('/Scripts2/Script2.js loaded'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System.IO; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.FileProviders; | ||
|
||
namespace WebOptimizer.Core.Sample2 | ||
{ | ||
public class Startup | ||
{ | ||
public IConfiguration Configuration { get; } | ||
public IHostingEnvironment HostingEnvironment { get; } | ||
|
||
public Startup(IConfiguration configuration, IHostingEnvironment hostingEnvironment) | ||
{ | ||
Configuration = configuration; | ||
HostingEnvironment = hostingEnvironment; | ||
} | ||
|
||
|
||
// This method gets called by the runtime. Use this method to add services to the container. | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddMvc(); | ||
|
||
|
||
var cssSettings = new CssBundlingSettings(); | ||
var codeSettings = new CodeBundlingSettings | ||
{ | ||
Minify = true, | ||
}; | ||
|
||
services.AddWebOptimizer(HostingEnvironment, cssSettings, codeSettings); | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseBrowserLink(); | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
else | ||
{ | ||
app.UseExceptionHandler("/Home/Error"); | ||
} | ||
|
||
const string scriptsPath1 = "Scripts1"; | ||
const string scriptsPath2 = "Scripts2"; | ||
|
||
var currentDirectory = Directory.GetCurrentDirectory(); | ||
app.UseWebOptimizer(HostingEnvironment, new[] | ||
{ | ||
new FileProviderOptions | ||
{ | ||
RequestPath = "/" + scriptsPath1, | ||
FileProvider = new PhysicalFileProvider(Path.Combine(currentDirectory, scriptsPath1)) | ||
}, | ||
new FileProviderOptions | ||
{ | ||
RequestPath = "/" + scriptsPath2, | ||
FileProvider = new PhysicalFileProvider(Path.Combine(currentDirectory, scriptsPath2)) | ||
}, | ||
new FileProviderOptions | ||
{ | ||
RequestPath = "/EmbeddedResourcesScripts", | ||
FileProvider = new EmbeddedFileProvider(Lib.AssemblyTools.GetCurrentAssembly()), | ||
} | ||
}); | ||
|
||
app.UseStaticFiles(); | ||
|
||
app.UseMvc(routes => | ||
{ | ||
routes.MapRoute( | ||
name: "default", | ||
template: "{controller=Home}/{action=Index}/{id?}"); | ||
}); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@{ | ||
ViewData["Title"] = "Home Page"; | ||
} | ||
|
||
<div id="content"> | ||
|
||
</div> | ||
|
||
<script type="text/javascript" src="~/Scripts1/Script1.js" asp-append-version="true" asp-bundle-key="bundle1"></script> | ||
|
||
<script type="text/javascript" src="~/Scripts2/Script2.js" asp-append-version="true" asp-bundle-key="bundle1"></script> | ||
|
||
<script type="text/javascript" src="~/js/Script3.js" asp-append-version="true" asp-bundle-key="bundle1"></script> | ||
|
||
<script type="text/javascript" src="~/EmbeddedResourcesScripts/EmbeddedScript1.js" asp-append-version="true" asp-bundle-key="bundle1"></script> | ||
|
||
<script type="text/javascript" src="~/EmbeddedResourcesScripts/Scripts/EmbeddedScript2.js" asp-append-version="true" asp-bundle-key="bundle1"></script> | ||
|
||
<script type="text/javascript" asp-bundle-dest-key="bundle1"></script> |
22 changes: 22 additions & 0 deletions
22
sample2/WebOptimizer.Core.Sample2/Views/Shared/Error.cshtml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@model ErrorViewModel | ||
@{ | ||
ViewData["Title"] = "Error"; | ||
} | ||
|
||
<h1 class="text-danger">Error.</h1> | ||
<h2 class="text-danger">An error occurred while processing your request.</h2> | ||
|
||
@if (Model.ShowRequestId) | ||
{ | ||
<p> | ||
<strong>Request ID:</strong> <code>@Model.RequestId</code> | ||
</p> | ||
} | ||
|
||
<h3>Development Mode</h3> | ||
<p> | ||
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred. | ||
</p> | ||
<p> | ||
<strong>Development environment should not be enabled in deployed applications</strong>, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>, and restarting the application. | ||
</p> |
14 changes: 14 additions & 0 deletions
14
sample2/WebOptimizer.Core.Sample2/Views/Shared/_Layout.cshtml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>@ViewData["Title"] - WebOptimizer.Core.Sample2</title> | ||
</head> | ||
<body> | ||
|
||
@RenderBody() | ||
|
||
|
||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@using WebOptimizer.Core.Sample2 | ||
@using WebOptimizer.Core.Sample2.Models | ||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers | ||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers | ||
@removeTagHelper Microsoft.AspNetCore.Mvc.TagHelpers.LinkTagHelper, Microsoft.AspNetCore.Mvc.TagHelpers | ||
@removeTagHelper Microsoft.AspNetCore.Mvc.TagHelpers.ScriptTagHelper, Microsoft.AspNetCore.Mvc.TagHelpers | ||
@addTagHelper WebOptimizer.TagHelpersDynamic.*, WebOptimizer.Core |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@{ | ||
Layout = "_Layout"; | ||
} |
20 changes: 20 additions & 0 deletions
20
sample2/WebOptimizer.Core.Sample2/WebOptimizer.Core.Sample2.csproj
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\WebOptimizer.Core\WebOptimizer.Core.csproj" /> | ||
<ProjectReference Include="..\WebOptimizer.Core.Sample2.Lib\WebOptimizer.Core.Sample2.Lib.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
10 changes: 10 additions & 0 deletions
10
sample2/WebOptimizer.Core.Sample2/appsettings.Development.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"Logging": { | ||
"IncludeScopes": false, | ||
"LogLevel": { | ||
"Default": "Debug", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"Logging": { | ||
"IncludeScopes": false, | ||
"LogLevel": { | ||
"Default": "Warning" | ||
} | ||
}, | ||
"webOptimizer": { | ||
"enableCaching": true, | ||
"enableTagHelperBundling": true | ||
//"cdnUrl": "https://my-cdn.com/" | ||
} | ||
} |
Oops, something went wrong.