Skip to content

Commit

Permalink
Use new templates and mostly get working on .NET 8
Browse files Browse the repository at this point in the history
  • Loading branch information
danielchalmers committed Mar 24, 2024
1 parent c5a18c3 commit ee30743
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 67 deletions.
4 changes: 2 additions & 2 deletions src/TryMudBlazor.Client/Pages/Index/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
A playground for <MudLink Typo="Typo.h4" Href="https://mudblazor.com" Target="_blank">MudBlazor</MudLink> @Version
</MudText>
<div class="px-2 mt-8">
<MudButton Variant="Variant.Filled" Color="Color.Primary" Size="Size.Large" DisableElevation="true" Class="px-6" Link="/snippet">Play now</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Primary" Size="Size.Large" DisableElevation="true" Class="px-6" Href="/snippet">Play now</MudButton>
</div>
</div>
</MudItem>
Expand All @@ -29,7 +29,7 @@
<MudText Typo="Typo.h5" Class="mud-text-secondary">
Play with MudBlazor components entirely in the browser. Test and experiment anytime, anywhere.
</MudText>
<MudButton Variant="Variant.Text" Color="Color.Primary" Size="Size.Large" Class="ml-n2" Link="/snippet" EndIcon="@Icons.Material.Filled.East">Get started</MudButton>
<MudButton Variant="Variant.Text" Color="Color.Primary" Size="Size.Large" Class="ml-n2" Href="/snippet" EndIcon="@Icons.Material.Filled.East">Get started</MudButton>
<MudPaper Elevation="25" Class="rounded-lg mt-12">
<div class="d-flex align-center py-2 try-mudblazor-codecard rounded-t-lg">
<div class="flex-grow-0 px-1">
Expand Down
82 changes: 41 additions & 41 deletions src/TryMudBlazor.Client/Pages/UserPage.razor
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
@page "/user-page"

<MudContainer Class="mt-8">
<MudText>This snippet hasn't been compiled yet.</MudText>
<MudText>Run the code on the left to see the result here.</MudText>
<MudText Typo="@Typo.h6" Class="mt-12">How to load your own service</MudText>
<MudText Class="mt-3">
To install a service which your snippet can use create a new *.cs file, <br/>
define a <code class="mud-primary-text">class UserStartup</code> with a <code class="mud-primary-text">public static void Configure(WebAssemblyHostBuilder builder)</code>.
</MudText>
<br/>
<MudText>Here is an example. Note the required usings!</MudText>
<pre class="mt-6">
namespace Try.UserComponents
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// required using for UserStartup:
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;

public class UserStartup
{
public static void Configure(WebAssemblyHostBuilder builder) {
builder.Services.AddSingleton(new MyService());
}
}

// your service
public class MyService {
public string Hello() => "Hello World from MyService!";
}

@page "/user-page"

<MudContainer Class="mt-8">
<MudText>This snippet hasn't been compiled yet.</MudText>
<MudText>Run the code on the left to see the result here.</MudText>
<MudText Typo="@Typo.h6" Class="mt-12">How to load your own service</MudText>
<MudText Class="mt-3">
To install a service which your snippet can use create a new *.cs file, <br/>
define a <code class="mud-primary-text">class UserStartup</code> with a <code class="mud-primary-text">public static void Configure(WebAssemblyHostBuilder builder)</code>.
</MudText>
<br/>
<MudText>Here is an example. Note the required usings!</MudText>
<pre class="mt-6">
namespace Try.UserComponents
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// required using for UserStartup:
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;

public class UserStartup
{
public static void Configure(WebAssemblyHostBuilder builder) {
builder.Services.AddSingleton(new MyService());
}
}

// your service
public class MyService {
public string Hello() => "Hello World from MyService!";
}

}
</pre>
</MudContainer>


</pre>
</MudContainer>


2 changes: 0 additions & 2 deletions src/TryMudBlazor.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public static class Program
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
//builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddSingleton(serviceProvider => (IJSInProcessRuntime)serviceProvider.GetRequiredService<IJSRuntime>());
builder.Services.AddSingleton(serviceProvider => (IJSUnmarshalledRuntime)serviceProvider.GetRequiredService<IJSRuntime>());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<Router AppAssembly="@typeof(Program).Assembly"
AdditionalAssemblies="@(new List<System.Reflection.Assembly> { typeof(Try.UserComponents.__Main).Assembly })"
@rendermode="new InteractiveWebAssemblyRenderMode(prerender: false)">
AdditionalAssemblies="@([typeof(Try.UserComponents.__Main).Assembly])">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(EmptyLayout)" />
</Found>
Expand All @@ -9,5 +8,4 @@
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
@* <HeadOutlet @rendermode="new InteractiveWebAssemblyRenderMode(prerender: false)"/> *@
</Router>
1 change: 1 addition & 0 deletions src/TryMudBlazor.Client/TryMudBlazor.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<PublishTrimmed>false</PublishTrimmed>
<UserSecretsId>4bb79e6f-9796-46cb-a3d0-31b21ac94f9a</UserSecretsId>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion src/TryMudBlazor.Client/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@
@using Microsoft.JSInterop
@using TryMudBlazor.Client.Components
@using TryMudBlazor.Client.Shared

@using MudBlazor
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
gtag('config', 'G-33J60J6E14');
</script>

<HeadOutlet @rendermode="new InteractiveWebAssemblyRenderMode(prerender: false)" />
</head>

<body class="mud-height-full">
Expand All @@ -57,7 +59,8 @@
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
<script src="_framework/blazor.webassembly.js"></script>
<Routes @rendermode="new InteractiveWebAssemblyRenderMode(prerender: false)" />
<script src="_framework/blazor.web.js"></script>
<script src="_content/MudBlazor/MudBlazor.min.js?v=#{CACHE_TOKEN}#"></script>
<script src="editor/main.js?v=#{CACHE_TOKEN}#"></script>
<script type="text/javascript">
Expand Down
17 changes: 1 addition & 16 deletions src/TryMudBlazor.Server/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using Microsoft.AspNetCore.Builder;
using MudBlazor.Examples.Data;
using TryMudBlazor.Client;
using TryMudBlazor.Client.Shared;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorComponents()
//.AddInteractiveServerComponents()
.AddInteractiveWebAssemblyComponents();

builder.Services.AddScoped<IPeriodicTableService, PeriodicTableService>();
Expand Down Expand Up @@ -36,25 +32,14 @@
}

app.UseHttpsRedirection();

app.UseRouting();

app.UseCors();

// Needed for wasm project
app.UseBlazorFrameworkFiles();
app.UseStaticFiles();

app.MapControllers();
// Serve the wasm project if no other matches
app.MapFallbackToFile("index.html");

app.UseStaticFiles();
app.UseAntiforgery();

app.MapRazorComponents<App>()
//.AddInteractiveServerRenderMode()
app.MapRazorComponents<TryMudBlazor.Server.App>()
.AddInteractiveWebAssemblyRenderMode();
//.AddAdditionalAssemblies(typeof(MainLayout).Assembly);

app.Run();
12 changes: 12 additions & 0 deletions src/TryMudBlazor.Server/_Imports.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using TryMudBlazor.Client
@using TryMudBlazor.Client.Components
@using TryMudBlazor.Client.Shared
@using MudBlazor

0 comments on commit ee30743

Please sign in to comment.