From cfd5b5f0f60227a0cf09cd73a8f70e2747581b43 Mon Sep 17 00:00:00 2001 From: Nathan Westfall Date: Sun, 14 Mar 2021 13:37:42 -0400 Subject: [PATCH 1/6] updated to support .net5 routing --- example/BlazorTenant.Example/App.razor | 7 +- .../BlazorTenant.Example.csproj | 14 +- .../Pages/Authentication.razor | 22 -- .../BlazorTenant.Example/Pages/Counter.razor | 2 +- .../Pages/FetchData.razor | 2 +- .../BlazorTenant.Example/Pages/Index.razor | 4 +- example/BlazorTenant.Example/Program.cs | 5 +- .../Properties/launchSettings.json | 5 +- .../Shared/MainLayout.razor | 27 +- .../Shared/MainLayout.razor.css | 70 +++++ .../Shared/NavMenu.razor.css | 62 +++++ .../Shared/RedirectToLogin.razor | 11 - .../Shared/SurveyPrompt.razor | 4 +- example/BlazorTenant.Example/_Imports.razor | 1 + .../BlazorTenant.Example/wwwroot/css/app.css | 145 +---------- .../BlazorTenant.Example/wwwroot/favicon.ico | Bin 32038 -> 5430 bytes .../BlazorTenant.Example/wwwroot/index.html | 3 +- .../wwwroot/sample-data/weather.json | 2 +- src/BlazorTenant/BlazorTenant.csproj | 17 +- src/BlazorTenant/IRouteTable.cs | 16 ++ src/BlazorTenant/ITenantStore.cs | 2 +- ...yMultiTenantOptionalTypeRouteContraint.cs} | 8 +- .../LegacyMultiTenantRouteConstraint.cs | 112 ++++++++ .../LegacyMultiTenantRouteEntry.cs | 132 ++++++++++ .../LegacyMultiTenantRouteTable.cs | 41 +++ .../LegacyMultiTenantRouteTableFactory.cs | 242 ++++++++++++++++++ .../LegacyMultiTenantRouteTemplate.cs | 24 ++ .../LegacyMultiTenantTemplateParser.cs | 108 ++++++++ .../LegacyMultiTenantTemplateSegment.cs | 122 +++++++++ .../LegacyMultiTenantTypeRouteConstraint.cs | 34 +++ .../MultiTenantNavigationContext.cs | 29 +++ .../MultiTenantRouteConstraint.cs | 31 +-- src/BlazorTenant/MultiTenantRouteContext.cs | 21 +- src/BlazorTenant/MultiTenantRouteEntry.cs | 171 +++++++------ src/BlazorTenant/MultiTenantRouteTable.cs | 16 +- .../MultiTenantRouteTableFactory.cs | 136 +++++----- src/BlazorTenant/MultiTenantRouteTemplate.cs | 5 +- src/BlazorTenant/MultiTenantRouter.cs | 121 ++++++++- src/BlazorTenant/MultiTenantTemplateParser.cs | 21 +- .../MultiTenantTemplateSegment.cs | 114 ++++++--- .../MultiTenantTypeRouteConstraint.cs | 22 +- src/BlazorTenant/Tenant.cs | 2 +- src/BlazorTenant/TenantStore.cs | 22 +- src/BlazorTenant/_Imports.razor | 1 - 44 files changed, 1503 insertions(+), 453 deletions(-) delete mode 100644 example/BlazorTenant.Example/Pages/Authentication.razor create mode 100644 example/BlazorTenant.Example/Shared/MainLayout.razor.css create mode 100644 example/BlazorTenant.Example/Shared/NavMenu.razor.css delete mode 100644 example/BlazorTenant.Example/Shared/RedirectToLogin.razor create mode 100644 src/BlazorTenant/IRouteTable.cs rename src/BlazorTenant/{MultiTenantOptionalTypeRouteContraint.cs => LegacyRouteMatching/LegacyMultiTenantOptionalTypeRouteContraint.cs} (76%) create mode 100644 src/BlazorTenant/LegacyRouteMatching/LegacyMultiTenantRouteConstraint.cs create mode 100644 src/BlazorTenant/LegacyRouteMatching/LegacyMultiTenantRouteEntry.cs create mode 100644 src/BlazorTenant/LegacyRouteMatching/LegacyMultiTenantRouteTable.cs create mode 100644 src/BlazorTenant/LegacyRouteMatching/LegacyMultiTenantRouteTableFactory.cs create mode 100644 src/BlazorTenant/LegacyRouteMatching/LegacyMultiTenantRouteTemplate.cs create mode 100644 src/BlazorTenant/LegacyRouteMatching/LegacyMultiTenantTemplateParser.cs create mode 100644 src/BlazorTenant/LegacyRouteMatching/LegacyMultiTenantTemplateSegment.cs create mode 100644 src/BlazorTenant/LegacyRouteMatching/LegacyMultiTenantTypeRouteConstraint.cs create mode 100644 src/BlazorTenant/MultiTenantNavigationContext.cs delete mode 100644 src/BlazorTenant/_Imports.razor diff --git a/example/BlazorTenant.Example/App.razor b/example/BlazorTenant.Example/App.razor index 0ae1695..caaa102 100644 --- a/example/BlazorTenant.Example/App.razor +++ b/example/BlazorTenant.Example/App.razor @@ -1,5 +1,5 @@ - - + + @@ -14,5 +14,4 @@ - - + \ No newline at end of file diff --git a/example/BlazorTenant.Example/BlazorTenant.Example.csproj b/example/BlazorTenant.Example/BlazorTenant.Example.csproj index 1fe6057..6e663d7 100644 --- a/example/BlazorTenant.Example/BlazorTenant.Example.csproj +++ b/example/BlazorTenant.Example/BlazorTenant.Example.csproj @@ -1,17 +1,13 @@ - + - netstandard2.1 - 3.0 + net5.0 - - - - - - + + + diff --git a/example/BlazorTenant.Example/Pages/Authentication.razor b/example/BlazorTenant.Example/Pages/Authentication.razor deleted file mode 100644 index e7acd16..0000000 --- a/example/BlazorTenant.Example/Pages/Authentication.razor +++ /dev/null @@ -1,22 +0,0 @@ -@page "/authentication/{action}" -@using Microsoft.AspNetCore.Components.WebAssembly.Authentication -@inject NavigationManager Navigation -@inject Tenant tenant - - - - Logging in... - - - - -@code { - [Parameter] - public string Action { get; set; } - - protected override void OnInitialized() - { - if(Action == "logout-callback") - Navigation.NavigateTo($"{Navigation.BaseUri}{tenant.Identifier}", true); - } -} \ No newline at end of file diff --git a/example/BlazorTenant.Example/Pages/Counter.razor b/example/BlazorTenant.Example/Pages/Counter.razor index a4d4af9..ea07ff3 100644 --- a/example/BlazorTenant.Example/Pages/Counter.razor +++ b/example/BlazorTenant.Example/Pages/Counter.razor @@ -1,4 +1,4 @@ -@page "/counter" +@page "/counter"

Counter

diff --git a/example/BlazorTenant.Example/Pages/FetchData.razor b/example/BlazorTenant.Example/Pages/FetchData.razor index bb011b2..6d2c6d1 100644 --- a/example/BlazorTenant.Example/Pages/FetchData.razor +++ b/example/BlazorTenant.Example/Pages/FetchData.razor @@ -1,4 +1,4 @@ -@page "/fetchdata" +@page "/fetchdata" @inject HttpClient Http

Weather forecast

diff --git a/example/BlazorTenant.Example/Pages/Index.razor b/example/BlazorTenant.Example/Pages/Index.razor index 759a3c4..cb8cc19 100644 --- a/example/BlazorTenant.Example/Pages/Index.razor +++ b/example/BlazorTenant.Example/Pages/Index.razor @@ -1,7 +1,7 @@ @page "/" @inject Tenant tenant -

Hello, @tenant.Identifier!

+

Hello, world!

Welcome to your new app. @@ -10,4 +10,4 @@ Welcome to your new app. @foreach(var prop in tenant.Parameters) {

@prop.Key: @prop.Value

-} \ No newline at end of file +} diff --git a/example/BlazorTenant.Example/Program.cs b/example/BlazorTenant.Example/Program.cs index 52abd5f..e3ed533 100644 --- a/example/BlazorTenant.Example/Program.cs +++ b/example/BlazorTenant.Example/Program.cs @@ -6,7 +6,6 @@ using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.AspNetCore.Components.WebAssembly.Authentication; using Microsoft.AspNetCore.Components.Authorization; @@ -23,7 +22,7 @@ public static async Task Main(string[] args) var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("app"); - builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); + builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); var store = new InMemoryTenantStore(); var tenantSection = builder.Configuration.GetSection("Tenants"); @@ -57,7 +56,7 @@ public static async Task Main(string[] args) options.ProviderOptions.DefaultScopes.Clear(); options.ProviderOptions.DefaultScopes.Add("openid profile offline_access api"); }); - + var build = builder.Build(); _sp = build.Services; build.Services.AddServiceProviderToMultiTenantRoutes(); diff --git a/example/BlazorTenant.Example/Properties/launchSettings.json b/example/BlazorTenant.Example/Properties/launchSettings.json index 5669105..2d0048e 100644 --- a/example/BlazorTenant.Example/Properties/launchSettings.json +++ b/example/BlazorTenant.Example/Properties/launchSettings.json @@ -3,8 +3,8 @@ "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:59832", - "sslPort": 44336 + "applicationUrl": "http://localhost:45311", + "sslPort": 44360 } }, "profiles": { @@ -18,6 +18,7 @@ }, "BlazorTenant.Example": { "commandName": "Project", + "dotnetRunMessages": "true", "launchBrowser": true, "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", "applicationUrl": "https://localhost:5001;http://localhost:5000", diff --git a/example/BlazorTenant.Example/Shared/MainLayout.razor b/example/BlazorTenant.Example/Shared/MainLayout.razor index cc88bc4..dc6c9c1 100644 --- a/example/BlazorTenant.Example/Shared/MainLayout.razor +++ b/example/BlazorTenant.Example/Shared/MainLayout.razor @@ -1,19 +1,18 @@ -@inherits LayoutComponentBase -@using Microsoft.AspNetCore.Components.WebAssembly.Authentication +@inherits LayoutComponentBase @inject Tenant tenant -@inject NavigationManager Navigation -@inject SignOutSessionStateManager SignOutManager - - -
-
- @(tenant?.Identifier ?? "N/A") +
+ -
- @Body +
+ + +
+ @Body +
-
\ No newline at end of file +
diff --git a/example/BlazorTenant.Example/Shared/MainLayout.razor.css b/example/BlazorTenant.Example/Shared/MainLayout.razor.css new file mode 100644 index 0000000..5c663e0 --- /dev/null +++ b/example/BlazorTenant.Example/Shared/MainLayout.razor.css @@ -0,0 +1,70 @@ +.page { + position: relative; + display: flex; + flex-direction: column; +} + +.main { + flex: 1; +} + +.sidebar { + background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%); +} + +.top-row { + background-color: #f7f7f7; + border-bottom: 1px solid #d6d5d5; + justify-content: flex-end; + height: 3.5rem; + display: flex; + align-items: center; +} + + .top-row ::deep a, .top-row .btn-link { + white-space: nowrap; + margin-left: 1.5rem; + } + + .top-row a:first-child { + overflow: hidden; + text-overflow: ellipsis; + } + +@media (max-width: 640.98px) { + .top-row:not(.auth) { + display: none; + } + + .top-row.auth { + justify-content: space-between; + } + + .top-row a, .top-row .btn-link { + margin-left: 0; + } +} + +@media (min-width: 641px) { + .page { + flex-direction: row; + } + + .sidebar { + width: 250px; + height: 100vh; + position: sticky; + top: 0; + } + + .top-row { + position: sticky; + top: 0; + z-index: 1; + } + + .main > div { + padding-left: 2rem !important; + padding-right: 1.5rem !important; + } +} diff --git a/example/BlazorTenant.Example/Shared/NavMenu.razor.css b/example/BlazorTenant.Example/Shared/NavMenu.razor.css new file mode 100644 index 0000000..e681f23 --- /dev/null +++ b/example/BlazorTenant.Example/Shared/NavMenu.razor.css @@ -0,0 +1,62 @@ +.navbar-toggler { + background-color: rgba(255, 255, 255, 0.1); +} + +.top-row { + height: 3.5rem; + background-color: rgba(0,0,0,0.4); +} + +.navbar-brand { + font-size: 1.1rem; +} + +.oi { + width: 2rem; + font-size: 1.1rem; + vertical-align: text-top; + top: -2px; +} + +.nav-item { + font-size: 0.9rem; + padding-bottom: 0.5rem; +} + + .nav-item:first-of-type { + padding-top: 1rem; + } + + .nav-item:last-of-type { + padding-bottom: 1rem; + } + + .nav-item ::deep a { + color: #d7d7d7; + border-radius: 4px; + height: 3rem; + display: flex; + align-items: center; + line-height: 3rem; + } + +.nav-item ::deep a.active { + background-color: rgba(255,255,255,0.25); + color: white; +} + +.nav-item ::deep a:hover { + background-color: rgba(255,255,255,0.1); + color: white; +} + +@media (min-width: 641px) { + .navbar-toggler { + display: none; + } + + .collapse { + /* Never collapse the sidebar for wide screens */ + display: block; + } +} diff --git a/example/BlazorTenant.Example/Shared/RedirectToLogin.razor b/example/BlazorTenant.Example/Shared/RedirectToLogin.razor deleted file mode 100644 index 1388e22..0000000 --- a/example/BlazorTenant.Example/Shared/RedirectToLogin.razor +++ /dev/null @@ -1,11 +0,0 @@ -@inject NavigationManager Navigation -@inject Tenant tenant - -@code { - protected override void OnInitialized() - { - Console.WriteLine("RedirectToLogin"); - Navigation.NavigateTo($"{tenant.Identifier}/authentication/login?returnUrl=" + - Uri.EscapeDataString(Navigation.Uri)); - } -} \ No newline at end of file diff --git a/example/BlazorTenant.Example/Shared/SurveyPrompt.razor b/example/BlazorTenant.Example/Shared/SurveyPrompt.razor index eb5635e..56d90d9 100644 --- a/example/BlazorTenant.Example/Shared/SurveyPrompt.razor +++ b/example/BlazorTenant.Example/Shared/SurveyPrompt.razor @@ -1,10 +1,10 @@ -