Skip to content

KhepriDotNet is a .NET library designed to address the complexities of state management in modern applications. By embracing Reactive Functional Programming (FRP), it offers an elegant and efficient way to handle state changes reactively and functionally.

License

Notifications You must be signed in to change notification settings

TheFo2sh/KhepriDotNet

Repository files navigation

KhepriDotNet

KhepriDotNet is a state-of-the-art .NET library tailored for efficient and flexible state management. It leverages Functional Reactive Programming (FRP) principles to facilitate responsive and maintainable application states.

Problem Definition

Managing state in applications can be challenging, especially in environments where state changes frequently and unpredictably. Traditional methods often lead to complicated and error-prone code.

Solution: Reactive Functional Programming

KhepriDotNet solves these challenges by combining the principles of FRP. This approach allows for more predictable state management, making your code more maintainable and responsive.

Features

  • Reactive State Management with Observables
  • Strong Emphasis on Immutability and Validation
  • Easy Integration with .NET Dependency Injection

Getting Started

To get started with KhepriDotNet, install the package via NuGet:

Install-Package KhepriDotNet

Implementing a Store

To create a store, define a class inheriting from Store<T> and use the [Action] attribute to mark methods modifying the state.

public class StudentRecordStore : Store<StudentRecord>
{
    [Action]
    public StudentRecord UpdateName(string name) 
    {
        return CurrentState with { Name = name };
    }

    [Action]
    public StudentRecord UpdateAge(int age) 
    {
        // Update age logic
    }
    
    protected override void Validate(StudentRecord state)
    {
        // Implement validation logic here
    }
}

Custom Validation for State Consistency

In KhepriDotNet, overriding the Validate method is crucial for maintaining state consistency. This custom validation process ensures that only valid data manipulates the state, preventing inconsistencies and potential errors in your application. It acts as a safeguard, allowing you to define rules and constraints that the state must adhere to.

protected override void Validate(StudentRecord state)
{
    // Implement validation logic here
}

By performing these checks before any state update, KhepriDotNet helps in maintaining a robust and reliable application, where state transitions are safe and predictable.


Registering a Store

Register your store with the .NET service collection for dependency injection:

services.AddStore<StudentRecordStore, StudentRecord>();

Subscribing to a Store

Subscribe to state changes in the store:

var store = serviceProvider.GetRequiredService<StudentRecordStore>();
store.Subscribe(state => {
    // React to state updates
});

About

KhepriDotNet is a .NET library designed to address the complexities of state management in modern applications. By embracing Reactive Functional Programming (FRP), it offers an elegant and efficient way to handle state changes reactively and functionally.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages