Avalonia Boilerplate
This commit is contained in:
parent
a6d5a3eb72
commit
0d32e6a5c3
14 changed files with 117 additions and 23 deletions
|
|
@ -6,6 +6,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageVersion Include="Avalonia" Version="11.0.7" />
|
<PackageVersion Include="Avalonia" Version="11.0.7" />
|
||||||
<PackageVersion Include="Avalonia.Desktop" Version="11.0.7" />
|
<PackageVersion Include="Avalonia.Desktop" Version="11.0.7" />
|
||||||
|
<PackageVersion Include="Avalonia.Fonts.Inter" Version="11.0.7" />
|
||||||
<PackageVersion Include="Avalonia.ReactiveUI" Version="11.0.7" />
|
<PackageVersion Include="Avalonia.ReactiveUI" Version="11.0.7" />
|
||||||
<PackageVersion Include="Avalonia.Themes.Fluent" Version="11.0.7" />
|
<PackageVersion Include="Avalonia.Themes.Fluent" Version="11.0.7" />
|
||||||
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.1" />
|
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.1" />
|
||||||
|
|
@ -19,6 +20,7 @@
|
||||||
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||||
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
|
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
|
||||||
<PackageVersion Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.0" />
|
<PackageVersion Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.0" />
|
||||||
|
<PackageVersion Include="ReactiveUI" Version="19.5.41" />
|
||||||
<PackageVersion Include="Splat.Microsoft.Extensions.DependencyInjection" Version="14.8.12" />
|
<PackageVersion Include="Splat.Microsoft.Extensions.DependencyInjection" Version="14.8.12" />
|
||||||
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||||
<PackageVersion Include="System.IO.Hashing" Version="8.0.0" />
|
<PackageVersion Include="System.IO.Hashing" Version="8.0.0" />
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
<Application xmlns="https://github.com/avaloniaui"
|
<Application xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:local="using:InkForge.Common"
|
|
||||||
x:Class="InkForge.Common.App"
|
x:Class="InkForge.Common.App"
|
||||||
RequestedThemeVariant="Default">
|
RequestedThemeVariant="Default">
|
||||||
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
|
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@ using Avalonia.Controls;
|
||||||
using Avalonia.Controls.ApplicationLifetimes;
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
|
|
||||||
|
using InkForge.Common.ViewModels;
|
||||||
|
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
|
|
||||||
namespace InkForge.Common;
|
namespace InkForge.Common;
|
||||||
|
|
@ -20,21 +24,15 @@ public partial class App : Application
|
||||||
|
|
||||||
public override void OnFrameworkInitializationCompleted()
|
public override void OnFrameworkInitializationCompleted()
|
||||||
{
|
{
|
||||||
// var viewModel = Services.Activate<MainViewModel>();
|
var viewModel = ActivatorUtilities.GetServiceOrCreateInstance<AppViewModel>(ServiceProvider);
|
||||||
// var view = ViewLocator.Current.ResolveView(viewModel);
|
var view = ViewLocator.Current.ResolveView(viewModel)!;
|
||||||
// switch (ApplicationLifetime)
|
view.ViewModel = viewModel;
|
||||||
// {
|
_ = ApplicationLifetime switch
|
||||||
// case IClassicDesktopStyleApplicationLifetime desktop:
|
{
|
||||||
// desktop.MainWindow = view as Window;
|
IClassicDesktopStyleApplicationLifetime desktop => desktop.MainWindow = view as Window,
|
||||||
// break;
|
ISingleViewApplicationLifetime singleView => singleView.MainView = view as Control,
|
||||||
|
_ => throw new NotSupportedException(),
|
||||||
// case ISingleViewApplicationLifetime singleView:
|
};
|
||||||
// singleView.MainView = view as Control;
|
|
||||||
// break;
|
|
||||||
|
|
||||||
// default:
|
|
||||||
// throw new NotSupportedException();
|
|
||||||
// }
|
|
||||||
|
|
||||||
base.OnFrameworkInitializationCompleted();
|
base.OnFrameworkInitializationCompleted();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
5
app/InkForge.Common/Controllers/WorkspaceController.cs
Normal file
5
app/InkForge.Common/Controllers/WorkspaceController.cs
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
namespace InkForge.Common.Controllers;
|
||||||
|
|
||||||
|
public class WorkspaceController
|
||||||
|
{
|
||||||
|
}
|
||||||
15
app/InkForge.Common/Data/NoteDbContextFactory.cs
Normal file
15
app/InkForge.Common/Data/NoteDbContextFactory.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
using InkForge.Data;
|
||||||
|
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace InkForge.Common.Data;
|
||||||
|
|
||||||
|
public class NoteDbContextFactory : IDbContextFactory<NoteDbContext>
|
||||||
|
{
|
||||||
|
|
||||||
|
public NoteDbContext CreateDbContext()
|
||||||
|
{
|
||||||
|
return new NoteDbContext(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Avalonia.Fonts.Inter" />
|
||||||
<PackageReference Include="Avalonia.ReactiveUI" />
|
<PackageReference Include="Avalonia.ReactiveUI" />
|
||||||
<PackageReference Include="Avalonia.Themes.Fluent" />
|
<PackageReference Include="Avalonia.Themes.Fluent" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
using InkForge.Common.Controllers;
|
||||||
|
using InkForge.Common.Data;
|
||||||
|
using InkForge.Data;
|
||||||
|
|
||||||
|
namespace Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
public static class InkForgeServiceCollections
|
||||||
|
{
|
||||||
|
public static IServiceCollection AddInkForge(this IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddHttpClient();
|
||||||
|
|
||||||
|
services.AddDbContextFactory<NoteDbContext, NoteDbContextFactory>();
|
||||||
|
|
||||||
|
services.AddSingleton<WorkspaceController>();
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
}
|
||||||
7
app/InkForge.Common/Properties/ConfigContext.cs
Normal file
7
app/InkForge.Common/Properties/ConfigContext.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace InkForge.Common.Properties;
|
||||||
|
|
||||||
|
[JsonSerializable(typeof(IDictionary<string, object>))]
|
||||||
|
[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Metadata)]
|
||||||
|
public partial class ConfigContext : JsonSerializerContext;
|
||||||
20
app/InkForge.Common/ViewModels/AppViewModel.cs
Normal file
20
app/InkForge.Common/ViewModels/AppViewModel.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
using InkForge.Common.Controllers;
|
||||||
|
|
||||||
|
using ReactiveUI;
|
||||||
|
|
||||||
|
namespace InkForge.Common.ViewModels;
|
||||||
|
|
||||||
|
public class AppViewModel : ReactiveObject
|
||||||
|
{
|
||||||
|
private object _view;
|
||||||
|
|
||||||
|
public object View
|
||||||
|
{
|
||||||
|
get => _view;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _view, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AppViewModel(WorkspaceController workspace)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
8
app/InkForge.Common/ViewModels/LandingViewModel.cs
Normal file
8
app/InkForge.Common/ViewModels/LandingViewModel.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
using ReactiveUI;
|
||||||
|
|
||||||
|
namespace InkForge.Common.ViewModels;
|
||||||
|
|
||||||
|
public class LandingViewModel : ReactiveObject
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.ReactiveUI;
|
using Avalonia.ReactiveUI;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
|
|
||||||
using InkForge.Common;
|
using InkForge.Common;
|
||||||
|
using InkForge.Data;
|
||||||
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
|
@ -23,6 +24,7 @@ static class Program
|
||||||
=> AppBuilder.Configure<App>()
|
=> AppBuilder.Configure<App>()
|
||||||
.UsePlatformDetect()
|
.UsePlatformDetect()
|
||||||
.UseReactiveUI()
|
.UseReactiveUI()
|
||||||
|
.WithInterFont()
|
||||||
.LogToTrace();
|
.LogToTrace();
|
||||||
|
|
||||||
private static void ConfigureServices(IServiceCollection services)
|
private static void ConfigureServices(IServiceCollection services)
|
||||||
|
|
@ -32,11 +34,7 @@ static class Program
|
||||||
mutableResolver.InitializeSplat();
|
mutableResolver.InitializeSplat();
|
||||||
mutableResolver.InitializeReactiveUI();
|
mutableResolver.InitializeReactiveUI();
|
||||||
|
|
||||||
services.AddHttpClient();
|
services.AddInkForge();
|
||||||
|
|
||||||
// services.UseFactories();
|
|
||||||
// services.AddViewModelFactory();
|
|
||||||
// services.AddTransient<IViewFor<MainViewModel>, MainWindow>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnSetup(this IServiceCollection services, AppBuilder appBuilder)
|
private static void OnSetup(this IServiceCollection services, AppBuilder appBuilder)
|
||||||
|
|
|
||||||
9
app/InkForge.Desktop/Views/MainWindow.axaml
Normal file
9
app/InkForge.Desktop/Views/MainWindow.axaml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<Window xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
x:Class="InkForge.Desktop.Views.MainWindow"
|
||||||
|
Title="InkForge">
|
||||||
|
|
||||||
|
</Window>
|
||||||
13
app/InkForge.Desktop/Views/MainWindow.axaml.cs
Normal file
13
app/InkForge.Desktop/Views/MainWindow.axaml.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
using Avalonia.ReactiveUI;
|
||||||
|
|
||||||
|
using InkForge.Common.ViewModels;
|
||||||
|
|
||||||
|
namespace InkForge.Desktop.Views;
|
||||||
|
|
||||||
|
public partial class MainWindow : ReactiveWindow<AppViewModel>
|
||||||
|
{
|
||||||
|
public MainWindow()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue