Skip to content

Commit

Permalink
Merge pull request #51 from BurkusCat/source-generators
Browse files Browse the repository at this point in the history
Source generator for BurkusMvvmApplication
  • Loading branch information
BurkusCat authored Nov 11, 2023
2 parents dea774b + a0efbbf commit b9b6dc6
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 259 deletions.
12 changes: 10 additions & 2 deletions CONTRIBUTING.MD
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
If an issue doesn't already exist, it is probably a good idea to raise an issue on the GitHub for the bug/feature suggestion (see above). If you were to spend time making changes without doing this, then your pull request may not be accepted if the change is not wanted or it is implemented in a way that the project does not want. Especially for more significant changes, it is always better to discuss a proposed implementation on an issue first.

## Pre-requisites
- [Visual Studio 2022 - 17.7.0 or greater](https://visualstudio.microsoft.com/vs/community/) with the .NET Multi-platform App UI workload installed
- [Visual Studio 2022 - 17.7.0 or greater](https://visualstudio.microsoft.com/vs/community/)
- Required: the .NET Multi-platform App UI workload installed
- Optional: the Visual Studio extension development workload installed (for debugging source generators)
- [XAML Styler](https://marketplace.visualstudio.com/items?itemName=TeamXavalon.XAMLStyler2022) for ensuring XAML is formatted consistently. It is a good idea to set it to run automatically on save.

NOTE: The above software is the recommended basics. You may be able to use other software versions or different pieces of software to contribute to this project.
Expand All @@ -34,4 +36,10 @@ NOTE: The above software is the recommended basics. You may be able to use other
- Try to rebase (`git rebase -i`) your PR onto `main` to tidy your git history https://www.atlassian.com/git/tutorials/rewriting-history/git-rebase
- Update the unit tests (fix any existing tests and ensure new code has unit test coverage)
- Update the sample app with the change/feature in action
- Ensure you have the [XAML Styler](https://marketplace.visualstudio.com/items?itemName=TeamXavalon.XAMLStyler2022) extension installed and have run it on any XAML files you have changed to format them
- Ensure you have the [XAML Styler](https://marketplace.visualstudio.com/items?itemName=TeamXavalon.XAMLStyler2022) extension installed and have run it on any XAML files you have changed to format them

## Source generators
### Debugging source generators
1. Set `Burkus.Mvvm.Maui.SourceGenerators` as your startup project.
2. Start debugging by running "Debug Source Gen Demo App" Debug mode.
3. Your breakpoints will now work in the source generator project.
20 changes: 6 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,17 @@ See the `DemoApp` in the `/samples` folder of this repository for a full example

## Getting started
1. Install `Burkus.Mvvm.Maui` into your main MAUI project from NuGet: <https://www.nuget.org/packages/Burkus.Mvvm.Maui> [![NuGet](https://img.shields.io/nuget/v/Burkus.Mvvm.Maui.svg?label=NuGet)](https://www.nuget.org/packages/Burkus.Mvvm.Maui/)
2. In your shared project's `App.xaml.cs`, remove any line where `MainPage` is set to a `Page` or an `AppShell`. Make `App` inherit from `BurkusMvvmApplication`. You should be left with a simpler `App` class like this:
2. In your shared project's `App.xaml.cs`, remove any line where `MainPage` is set to a `Page` or an `AppShell`. You should be left with a simpler `App` class like this:
``` csharp
public partial class App : BurkusMvvmApplication
public partial class App : Application
{
public App()
{
InitializeComponent();
}
}
```
3. Update `App.xaml` in your shared project to be a `burkus:BurkusMvvmApplication`.
``` xml
<?xml version="1.0" encoding="UTF-8" ?>
<burkus:BurkusMvvmApplication
...
xmlns:burkus="http://burkus.co.uk">
...
</burkus:BurkusMvvmApplication>
```
4. In your `MauiProgram.cs` file, call `.UseBurkusMvvm()` in your builder creation e.g.:
3. In your `MauiProgram.cs` file, call `.UseBurkusMvvm()` in your builder creation e.g.:

```csharp
public static class MauiProgram
Expand All @@ -90,7 +81,7 @@ public static class MauiProgram
})
...
```
5. **💡 RECOMMENDED**: This library pairs great with the amazing `CommunityToolkit.Mvvm`. Follow its [Getting started](https://learn.microsoft.com/en-us/dotnet/communitytoolkit/mvvm/#getting-started) guide to add it.
4. **💡 RECOMMENDED**: This library pairs great with the amazing `CommunityToolkit.Mvvm`. Follow its [Getting started](https://learn.microsoft.com/en-us/dotnet/communitytoolkit/mvvm/#getting-started) guide to add it.
## Registering views, viewmodels, and services
A recommended way to register your views, viewmodels, and services is by creating extension methods in your `MauiProgram.cs` file.
Expand Down Expand Up @@ -411,7 +402,8 @@ See the [IDialogService interface in the repository](https://github.com/BurkusCa
## Advanced / complexities
The below are some things of note that may help prevent issues from arising:
- When you inherit from `BurkusMvvmApplication`, the `MainPage` of the app will be automatically set to a `NavigationPage`. This means the first page you push can be a `ContentPage` rather than needing to push a `NavigationPage`. This may change in the future.
- The `MainPage` of the app will be automatically set to a `NavigationPage`. This means the first page you push can be a `ContentPage` rather than needing to push a `NavigationPage`. This may change in the future.
- A source generator will automatically add code overriding `Window CreateWindow(IActivationState? activationState)` in your `App.xaml.cs` class.
- Adding this package to a project will automatically import the `Burkus.Mvvm.Maui` namespace globally if you have [`ImplicitUsings`](https://devblogs.microsoft.com/dotnet/welcome-to-csharp-10/#implicit-usings) enabled in your project. You can opt out of this by including the following in your `.csproj` file:
``` xml
<Using Remove="Burkus.Mvvm.Maui" />
Expand Down
12 changes: 5 additions & 7 deletions samples/DemoApp/App.xaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<burkus:BurkusMvvmApplication
<Application
x:Class="DemoApp.App"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:burkus="http://burkus.co.uk"
xmlns:local="clr-namespace:DemoApp">
<burkus:BurkusMvvmApplication.Resources>
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/DemoAppStyles.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</burkus:BurkusMvvmApplication.Resources>
</burkus:BurkusMvvmApplication>
</Application.Resources>
</Application>
2 changes: 1 addition & 1 deletion samples/DemoApp/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace DemoApp;

public partial class App : BurkusMvvmApplication
public partial class App : Application
{
public App()
{
Expand Down
Loading

0 comments on commit b9b6dc6

Please sign in to comment.