Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mrousavy/jellyfish
🐟 An incredibly lightweight and type safe MVVM library for .NET WPF, Silverlight, Xamarin and UWP
https://github.com/mrousavy/jellyfish
csharp dotnet enum fish jellyfish library light modern mvvm notifying-properties preferences silverlight uwp wpf xamarin
Last synced: about 5 hours ago
JSON representation
🐟 An incredibly lightweight and type safe MVVM library for .NET WPF, Silverlight, Xamarin and UWP
- Host: GitHub
- URL: https://github.com/mrousavy/jellyfish
- Owner: mrousavy
- License: mit
- Created: 2018-05-13T10:42:47.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T00:58:14.000Z (almost 2 years ago)
- Last Synced: 2024-05-02T00:59:18.303Z (6 months ago)
- Topics: csharp, dotnet, enum, fish, jellyfish, library, light, modern, mvvm, notifying-properties, preferences, silverlight, uwp, wpf, xamarin
- Language: C#
- Homepage:
- Size: 1.23 MB
- Stars: 20
- Watchers: 4
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
Jellyfish
🐟
An incredibly light and type safe MVVM library for .NET WPF, Silverlight, Xamarin and UWP
Jellyfish is on [NuGet](https://www.nuget.org/packages/Jellyfish/):
```pm
PM> Install-Package Jellyfish
```> Make sure to also check out the [**Jellyfish Visual Studio Extension 📦**](https://github.com/mrousavy/Jellyfish/wiki/Jellyfish-VSIX)!
Compared to other **MVVM Frameworks** like [MVVM Light](http://www.mvvmlight.net/), [Prism](https://github.com/PrismLibrary/Prism) or [Caliburn.Micro](https://caliburnmicro.com/), this framework is
* as light as possible
* using modern best-practices
* using modern code style
* using little to no runtime reflection to be as fast as possible
* exactly fitting my needs# Usage
For description, documentation and usage, please view the [Jellyfish wiki 📖](https://github.com/mrousavy/Jellyfish/wiki) or the [Getting Started guide 📖](https://github.com/mrousavy/Jellyfish/wiki/Getting-started). For usage-example projects, please see [Jellyfish.Demo](https://github.com/mrousavy/Jellyfish/tree/master/src/Jellyfish.Demo) or [GameFinder](https://github.com/mrousavy/GameFinder).
## 📝 View Models
Every **ViewModel** needs to implement the [`ViewModel`](https://github.com/mrousavy/Jellyfish/blob/master/src/Jellyfish/ViewModel.cs) class:
```cs
public class LoginViewModel : ViewModel
{
private User _user;
public User User
{
get => _user;
set => Set(ref _user, value);
}
}
```> See [View Models 📖](https://github.com/mrousavy/Jellyfish/wiki/📝-View-Models)
## ⚡ Commands
The [`RelayCommand`](https://github.com/mrousavy/Jellyfish/blob/master/src/Jellyfish/RelayCommand.cs) is an [`ICommand`](https://msdn.microsoft.com/en-us/library/system.windows.input.icommand(v=vs.110).aspx) implementation.```xaml
```
Initialize the `ICommand` with a non-generic `RelayCommand` instance and the given action/callback:
```cs
ICommand LoginCommand = new RelayCommand(LoginAction, CanLogin);
// ...
void LoginAction(object parameter)
{ ... }
bool CanLogin(object parameter)
{ ... }
```> See [Commands 📖](https://github.com/mrousavy/Jellyfish/wiki/⚡-Commands)
## 💉 Dependency Injection
Provide dependencies for types using the [`IInjector`](https://github.com/mrousavy/Jellyfish/blob/master/src/Jellyfish/DependencyInjection/IInjector.cs)At app startup:
```cs
Injector.Register(() => new User("John", "Smith"));
Injector.Register(() => OpenDatabaseService(username, password));
```
Some ViewModel:
```cs
class LoginViewModel : ViewModel
{
IUser User { get; set; }
IDatabaseService _service;LoginViewModel()
{
this.Inject();
}
}
```> See [Dependency Injection 📖](https://github.com/mrousavy/Jellyfish/wiki/%F0%9F%92%89-Dependency-Injection)
## 💾 Enums
The enum binding source extension allows for better binding support on enums.Just use the [`EnumBindingSource` extension](https://github.com/mrousavy/Jellyfish/blob/master/src/Jellyfish/Extensions/EnumBindingSourceExtension.cs) to bind an enum to any `ItemsSource`:
```xaml```
> See [Enums 📖](https://github.com/mrousavy/Jellyfish/wiki/💾-Enums)
## ⚙️ Preferences
An abstract class definition for any application [`Preferences`](https://github.com/mrousavy/Jellyfish/blob/master/src/Jellyfish/Preferences.cs).```cs
public class DemoPreferences : Preferences
{
public int SomeInt { get; set; } = 400;
public string SomeString { get; set; } = "test string";
public bool SomeBool { get; set; } = false;public object SomeObject { get; set; } = new
{
Name = "Marc",
IsValid = true
};
}
```> See [Preferences 📖](https://github.com/mrousavy/Jellyfish/wiki/⚙️-Preferences)
## 🔔 Feeds
The [`IFeed`](https://github.com/mrousavy/Jellyfish/blob/master/src/Jellyfish/Feeds/IFeed.cs) allows notifying any subscribers in this feed about sudden changes within the application domain in realtime.```cs
class CustomViewModel : INode
{
public CustomViewModel
{
this.Subscribe();
}public void MessageReceived(NotifyReason reason)
{ ... }
}Feed.Notify(NotifyReason.RefreshView);
```> See [Feeds 📖](https://github.com/mrousavy/Jellyfish/wiki/🔔-Feeds)
# Results
### With Jellyfish
```cs
public class LoginViewModel : ViewModel
{
private User _user;
public User User
{
get => _user;
set => Set(ref _user, value);
}
}
```### Without Jellyfish
```cs
public class LoginViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}private string _username;
public string Username
{
get
{
return _username;
}
set
{
_username = value;
OnPropertyChanged("Username");
}
}
}
```