Skip to content

Commit

Permalink
Add BlazorBindingsApplication (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamescaper authored Jan 2, 2023
1 parent 0394da7 commit c0140d4
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 105 deletions.
15 changes: 0 additions & 15 deletions samples/BlazorBindingsToDo/App.cs

This file was deleted.

2 changes: 1 addition & 1 deletion samples/BlazorBindingsToDo/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiApp<BlazorBindingsApplication<TodoApp>>()
.UseMauiBlazorBindings();

builder.Services.AddSingleton<AppState>();
Expand Down
15 changes: 0 additions & 15 deletions samples/BlazorBindingsXaminals/App.cs

This file was deleted.

2 changes: 1 addition & 1 deletion samples/BlazorBindingsXaminals/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiApp<BlazorBindingsApplication<AppShell>>()
.UseMauiBlazorBindings()
.ConfigureFonts(fonts =>
{
Expand Down
15 changes: 0 additions & 15 deletions samples/ControlGallery/App.cs

This file was deleted.

2 changes: 1 addition & 1 deletion samples/ControlGallery/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiApp<BlazorBindingsApplication<AppShell>>()
.UseSkiaSharp()
.UseMauiBlazorBindings()
.ConfigureFonts(fonts =>
Expand Down
12 changes: 0 additions & 12 deletions samples/FluxorSample/App.cs

This file was deleted.

2 changes: 1 addition & 1 deletion samples/FluxorSample/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiApp<BlazorBindingsApplication<AppShell>>()
.UseMauiBlazorBindings()
.ConfigureFonts(fonts =>
{
Expand Down
13 changes: 0 additions & 13 deletions samples/FlyoutPageSample/App.cs

This file was deleted.

3 changes: 2 additions & 1 deletion samples/FlyoutPageSample/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BlazorBindings.Maui;
using FlyoutPageSample.Views;

namespace FlyoutPageSample
{
Expand All @@ -7,7 +8,7 @@ public static class MauiProgram
public static MauiApp CreateMauiApp()
{
return MauiApp.CreateBuilder()
.UseMauiApp<App>()
.UseMauiApp<BlazorBindingsApplication<MainPage>>()
.UseMauiBlazorBindings()
.Build();
}
Expand Down
16 changes: 0 additions & 16 deletions samples/ThirdPartyControlsSample/App.cs

This file was deleted.

2 changes: 1 addition & 1 deletion samples/ThirdPartyControlsSample/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiApp<BlazorBindingsApplication<AppShell>>()
.UseMauiBlazorBindings()
.UseMauiCommunityToolkit()
.ConfigureFonts(fonts =>
Expand Down
16 changes: 16 additions & 0 deletions src/BlazorBindings.Maui/BlazorBindingsApplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui.Controls;
using System;

namespace BlazorBindings.Maui
{
public class BlazorBindingsApplication<T> : Application where T : IComponent
{
public BlazorBindingsApplication(IServiceProvider services)
{
var renderer = services.GetRequiredService<MauiBlazorBindingsRenderer>();
_ = renderer.AddComponent<T>(this);
}
}
}
6 changes: 5 additions & 1 deletion src/BlazorBindings.Maui/Navigation/Navigation.Shell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ public async Task NavigateToAsync(string uri, Dictionary<string, object> paramet
//TODO This route matching could be better. Can we use the ASPNEt version?
private List<StructuredRoute> FindRoutes()
{
var appType = MC.Application.Current.GetType();
var assembly = appType.IsGenericType && appType.GetGenericTypeDefinition() == typeof(BlazorBindingsApplication<>)
? appType.GenericTypeArguments[0].Assembly
: appType.Assembly;

var result = new List<StructuredRoute>();
var assembly = MC.Application.Current.GetType().Assembly;
var pages = assembly.GetTypes().Where(x => x.IsSubclassOf(typeof(ComponentBase)));
foreach (var page in pages)
{
Expand Down
11 changes: 0 additions & 11 deletions templates/BlazorBindingsMaui-app/NewApp/App.cs

This file was deleted.

2 changes: 1 addition & 1 deletion templates/BlazorBindingsMaui-app/NewApp/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiApp<BlazorBindingsApplication<AppShell>>()
.UseMauiBlazorBindings()
.ConfigureFonts(fonts =>
{
Expand Down

0 comments on commit c0140d4

Please sign in to comment.