NittyGritty.Uno.SourceGenerators 1.2.0

dotnet add package NittyGritty.Uno.SourceGenerators --version 1.2.0
NuGet\Install-Package NittyGritty.Uno.SourceGenerators -Version 1.2.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NittyGritty.Uno.SourceGenerators" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NittyGritty.Uno.SourceGenerators --version 1.2.0
#r "nuget: NittyGritty.Uno.SourceGenerators, 1.2.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NittyGritty.Uno.SourceGenerators as a Cake Addin
#addin nuget:?package=NittyGritty.Uno.SourceGenerators&version=1.2.0

// Install NittyGritty.Uno.SourceGenerators as a Cake Tool
#tool nuget:?package=NittyGritty.Uno.SourceGenerators&version=1.2.0

Nitty Gritty Uno Source Generators

Please read the documentation for Nitty Gritty Source Generator Annotations first before proceeding.

This package contains the following source generators:

Locator Generator

Generate a Locator class that will configure your NavigationService, DialogService, view models, and other services by annotating your classes with [Locator], [Page], [Dialog], or [Instance] attributes.

Notes

  • Change the instance lifetime of your NavigationService by setting the NavigationServiceLifetime property of LocatorAttribute.
  • Match your view models and pages by annotating your pages with PageAttribute and your view models with ViewModelKeyAttribute. The generator uses the convention HomeViewModelHomePage or HomeView. You can override this by setting the Key properties of the attributes.
  • Match your view models and dialogs by annotating your dialogs with DialogAttribute and your view models with DialogKeyAttribute. The generator uses the convention AddUserViewModelAddUserDialog or AddUserView. You can override this by setting the Key properties of the attributes.
  • Customize your [Instance] annotated classes by setting the following properties:
    • Lifetime (Change the lifetime of the instance to Singleton, Scoped, or Transient. default: Singleton)
    • Parent (Set the parent type of the instance that you want the Locator to use when referencing your instance)
    • Name (Set the property name of the instance inside the Locator class. This will only be used when Lifetime is set to Singleton)
  • Configure additional services by adding an implementation to the generated partial method Configure(ServiceCollection services).

Example:

[Locator]
public partial class Locator { /* ... */ }

[Page]
public partial class HomePage : NGPage { /* ... */ }

[Instance, ViewModelKey]
public class HomeViewModel : ViewModelBase { /* ... */ }

[Dialog]
public partial class AddUserDialog : ContentDialog { /* ... */ }

[DialogKey]
public class AddUserViewModel : ObservableObject { /* ... */ }

[Instance(Parent = typeof(IUserService))]
public class UserService : IUserService { /* ... */ }

This will generate:

public partial class Locator
{
    private readonly ServiceProvider provider;

    public Locator()
    {
        var services = new ServiceCollection();

        services.AddSingleton<INavigationService>(isp =>
        {
            var navigationService = new NavigationService();
            navigationService.Configure("Home", typeof(HomePage));
            return navigationService;
        });

        services.AddSingleton<IDialogService>(isp =>
        {
            var dialogService = new DialogService();
            dialogService.Configure("AddUser", typeof(AddUserDialog));
            return dialogService;
        });

        services.AddSingleton<HomeViewModel>();
        services.AddSingleton<IUserService, UserService>();

        Configure(services);
        provider = services.BuildServiceProvider();
    }

    partial void Configure(ServiceCollection services);

    public HomeViewModel Home => provider.GetService<HomeViewModel>();
    public IUserService UserService => provider.GetService<IUserService>();
}

Page Generator

Generate ViewModel properties inside of your Pages that you can use in XAML binding. Your Page's PageAttribute and your view model's ViewModelKeyAttribute should have matching Keys.

Example:

[Page]
public partial class HomePage : NGPage { /* ... */ }

[ViewModelKey]
public class HomeViewModel : ViewModelBase { /* ... */ }

This will generate:

public partial class HomePage
{
    public HomeViewModel ViewModel => DataContext as HomeViewModel;
}

Dialog Generator

Generate ViewModel properties inside of your ContentDialogs that you can use in XAML binding. Your Dialog's DialogAttribute and your view model's DialogKeyAttribute should have matching Keys.

Example:

[Dialog]
public partial class AddUserDialog : ContentDialog { /* ... */ }

[DialogKey]
public class AddUserViewModel : ObservableObject { /* ... */ }

This will generate:

public partial class AddUserDialog
{
    public AddUserViewModel ViewModel => DataContext as AddUserViewModel;
}

NOTES

Don't forget to make your classes partial when using the [Locator], [Page] and [Dialog] attributes. If the generated source code is not being updated even after doing a clean and rebuild, try restarting Visual Studio.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.0 582 1/27/2022
1.1.0 515 1/26/2022