{"id":13629496,"url":"https://github.com/thomasclaudiushuber/mvvmgen","last_synced_at":"2025-04-04T07:09:38.191Z","repository":{"id":41447703,"uuid":"361756791","full_name":"thomasclaudiushuber/mvvmgen","owner":"thomasclaudiushuber","description":"MvvmGen is a lightweight MVVM library for XAML applications. It generates your ViewModels on-the-fly for you via a Roslyn-based C# Source Generator.","archived":false,"fork":false,"pushed_at":"2023-12-12T18:53:55.000Z","size":764,"stargazers_count":255,"open_issues_count":8,"forks_count":21,"subscribers_count":14,"default_branch":"main","last_synced_at":"2024-10-30T01:02:44.687Z","etag":null,"topics":["avaloniaui","c-sharp","csharp","dotnet","dotnet-standard","maui","mvvm","source-generator","uno","uno-platform","winui","wpf","xamarin-forms","xaml"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thomasclaudiushuber.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-04-26T13:17:22.000Z","updated_at":"2024-10-23T13:02:58.000Z","dependencies_parsed_at":"2023-11-25T11:20:53.674Z","dependency_job_id":"98194fbb-2f48-41c6-ad82-396de1db2d20","html_url":"https://github.com/thomasclaudiushuber/mvvmgen","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasclaudiushuber%2Fmvvmgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasclaudiushuber%2Fmvvmgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasclaudiushuber%2Fmvvmgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasclaudiushuber%2Fmvvmgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thomasclaudiushuber","download_url":"https://codeload.github.com/thomasclaudiushuber/mvvmgen/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247135147,"owners_count":20889421,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["avaloniaui","c-sharp","csharp","dotnet","dotnet-standard","maui","mvvm","source-generator","uno","uno-platform","winui","wpf","xamarin-forms","xaml"],"created_at":"2024-08-01T22:01:12.101Z","updated_at":"2025-04-04T07:09:38.168Z","avatar_url":"https://github.com/thomasclaudiushuber.png","language":"C#","funding_links":[],"categories":["Content","Source Generators"],"sub_categories":["228. [mvvmgen](https://ignatandrei.github.io/RSCG_Examples/v2/docs/mvvmgen) , in the [Serializer](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#serializer) category","XAML / WPF / Avalonia"],"readme":"# ⚡ MvvmGen \n\n[![Build MvvmGen](https://github.com/thomasclaudiushuber/mvvmgen/actions/workflows/build_mvvmgen.yml/badge.svg)](https://github.com/thomasclaudiushuber/mvvmgen/actions/workflows/build_mvvmgen.yml)\n[![NuGet MvvmGen](https://img.shields.io/nuget/v/MvvmGen.svg?label=NuGet%20MvvmGen)](https://www.nuget.org/packages/Mvvmgen)\n[![NuGet MvvmGen](https://img.shields.io/nuget/v/MvvmGen.PureCodeGeneration.svg?label=NuGet%20MvvmGen.PureCodeGeneration)](https://www.nuget.org/packages/Mvvmgen.PureCodeGeneration)\n\n## Your Friend Who Writes the Boilerplate for You\n\nHey there, welcome to the **MvvmGen** repository. **MvvmGen** is a lightweight \nand modern MVVM library (.NET Standard 2.0) built with C# Source Generators\nthat helps you to apply the popular Model-View-ViewModel-pattern (MVVM) \nin your XAML applications that you build with WPF, WinUI, Uno Platform, \nAvalonia, Xamarin Forms, or .NET MAUI.\n\nMvvmGen is licensed under the [MIT license](LICENSE).\n\n## Get Started\n\n- [Documentation](docs/00_start_here.md)\n- [Samples](https://github.com/thomasclaudiushuber/mvvmgen-samples)\n- [Blog post that introduces MvvmGen](https://www.thomasclaudiushuber.com/2021/05/12/introducing-the-mvvmgen-library)\n- [Blog post about pure code generation](https://www.thomasclaudiushuber.com/2021/05/19/mvvmgen-the-special-edition-pure-code-generation)\n\n## Quick intro\n\nIn this quick intro, you'll learn that creating a ViewModel is a lot of fun with **MvvmGen**! 🔥 \n\n### Installing the MvvmGen NuGet Package \nReference the NuGet package [MvvmGen](https://www.nuget.org/packages/MvvmGen/) \nin your .NET application, and then you're ready to go:\n```\nInstall-Package MvvmGen\n```  \n\nMvvmGen will register itself as a C# source generator in your project, \nand it will be your friend who writes the boilerplate for you.\n\n### Generating a ViewModel class\n\nTo generate a ViewModel class, you create a new class, you mark it as `partial`,\nand you put MvvmGen's `ViewModel` attribute on the class:\n\n```csharp\nusing MvvmGen;\n\nnamespace MyWpfApp.ViewModel\n{\n  [ViewModel]\n  public partial class EmployeeViewModel\n  {\n  }\n}\n```\n\nThe `ViewModel` attribute tells MvvmGen to generate another\n partial `EmployeeViewModel` class. Right now, it will be a class \nthat looks like this:\n\n```csharp\nusing MvvmGen.Commands;\nusing MvvmGen.Events;\nusing MvvmGen.ViewModels;\n\nnamespace MyWpfApp.ViewModel\n{\n    partial class EmployeeViewModel : ViewModelBase\n    {\n        public EmployeeViewModel()\n        {\n            this.OnInitialize();\n        }\n\n        partial void OnInitialize();\n    }\n}\n```\n\nYou can see that generated class in Visual Studio under Dependencies-\u003eAnalyzers:\n![Generated class](docs/images/generate_a_viewModel_01.png)\n\nBeside the `ViewModel` attribute, you find many other attributes in the `MvvmGen` namespace \nthat you can use to decorate your ViewModel class. These attributes allow you to \nbuild a full ViewModel like this:\n\n```csharp\nusing MvvmGen;\nusing MvvmGen.Events;\n\nnamespace MyWpfApp.ViewModel\n{\n  public record EmployeeSavedEvent(string FirstName, string LastName);\n\n  [Inject(typeof(IEventAggregator))]\n  [ViewModel]\n  public partial class EmployeeViewModel\n  {\n    [Property] private string _firstName;\n    [Property] private string _lastName;\n\n    [Command(CanExecuteMethod = nameof(CanSave))]\n    private void Save()\n    {\n      EventAggregator.Publish(new EmployeeSavedEvent(FirstName, LastName));\n    }\n\n    [CommandInvalidate(nameof(FirstName))]\n    private bool CanSave()\n    {\n      return !string.IsNullOrEmpty(FirstName);\n    }\n  }\n}\n```\nFor this ViewModel, MvvmGen will generate the following partial class definition for you\n```csharp\nusing MvvmGen.Commands;\nusing MvvmGen.Events;\nusing MvvmGen.ViewModels;\n\nnamespace MyWpfApp.ViewModel\n{\n  partial class EmployeeViewModel : ViewModelBase\n  {\n    private IDelegateCommand? _saveCommand;\n\n    public EmployeeViewModel(MvvmGen.Events.IEventAggregator eventAggregator)\n    {\n      this.EventAggregator = eventAggregator;\n      this.OnInitialize();\n    }\n\n    partial void OnInitialize();\n\n    public IDelegateCommand SaveCommand =\u003e _saveCommand ??= new DelegateCommand(_ =\u003e Save(), _ =\u003e CanSave());\n\n    public string FirstName\n    {\n      get =\u003e _firstName;\n      set\n      {\n        if (_firstName != value)\n        {\n          _firstName = value;\n          OnPropertyChanged(\"FirstName\");\n        }\n      }\n    }\n\n    public string LastName\n    {\n      get =\u003e _lastName;\n      set\n      {\n        if (_lastName != value)\n        {\n          _lastName = value;\n          OnPropertyChanged(\"LastName\");\n        }\n      }\n    }\n\n    protected MvvmGen.Events.IEventAggregator EventAggregator { get; private set; }\n    \n    protected override void InvalidateCommands(string? propertyName)\n    {\n      base.InvalidateCommands(propertyName);\n      if(propertyName == \"FirstName\")\n      {\n          SaveCommand.RaiseCanExecuteChanged();\n      }\n    }\n  }\n}\n```\n\nTo learn all the details, go to the [documentation in this repo](docs/00_start_here.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomasclaudiushuber%2Fmvvmgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthomasclaudiushuber%2Fmvvmgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomasclaudiushuber%2Fmvvmgen/lists"}