{"id":18129129,"url":"https://github.com/saileshrijal/blazorstateprovider","last_synced_at":"2025-10-05T14:58:25.232Z","repository":{"id":259067705,"uuid":"876237724","full_name":"saileshrijal/BlazorStateProvider","owner":"saileshrijal","description":"A lightweight state management library for Blazor applications. Easily manage global and scoped states with support for session and local storage.","archived":false,"fork":false,"pushed_at":"2024-11-01T08:05:54.000Z","size":157,"stargazers_count":5,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-28T16:46:35.462Z","etag":null,"topics":["blazor","blazor-components","blazor-webassembly","csharp","dependency-injection","dotnet","local-storage","opensource","session-storage","state-management","state-persistence","web-development"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/BlazorStateProvider","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/saileshrijal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-21T16:19:20.000Z","updated_at":"2024-11-06T21:49:05.000Z","dependencies_parsed_at":"2024-11-01T08:17:56.844Z","dependency_job_id":"4e496313-7158-421d-b140-22ea74fc7b07","html_url":"https://github.com/saileshrijal/BlazorStateProvider","commit_stats":null,"previous_names":["saileshrijal/blazorstatemanager","saileshrijal/blazorstateprovider"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/saileshrijal/BlazorStateProvider","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saileshrijal%2FBlazorStateProvider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saileshrijal%2FBlazorStateProvider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saileshrijal%2FBlazorStateProvider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saileshrijal%2FBlazorStateProvider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saileshrijal","download_url":"https://codeload.github.com/saileshrijal/BlazorStateProvider/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saileshrijal%2FBlazorStateProvider/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278470181,"owners_count":25992203,"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","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["blazor","blazor-components","blazor-webassembly","csharp","dependency-injection","dotnet","local-storage","opensource","session-storage","state-management","state-persistence","web-development"],"created_at":"2024-11-01T10:06:05.543Z","updated_at":"2025-10-05T14:58:25.214Z","avatar_url":"https://github.com/saileshrijal.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BlazorStateProvider\n\nBlazorStateProvider is a state management library for Blazor applications that simplifies the management of state using local and session storage. It provides a clean and easy-to-use API for managing application state across components, ensuring that state is persisted as needed.\n\n## Features\n\n- **State Persistence**: Supports both local and session storage for persisting application state, allowing you to maintain state across user sessions or just within a single session.\n\n- **Simple API**: Provides a straightforward interface for managing state with methods to get, set, remove, and reset state, making it easy to use throughout your Blazor application.\n\n- **State Change Notifications**: Implements a subscription mechanism that notifies components of state changes, enabling a reactive programming model for better UI updates.\n\n- **Type Safety**: Utilizes generics to ensure type-safe state management, reducing the risk of runtime errors when retrieving and storing state values.\n\n\n## Installation\n\nYou can install the BlazorStateProvider NuGet package using the .NET CLI:\n\n```bash\ndotnet add package BlazorStateProvider\n```\nOr by adding it via the NuGet Package Provider in Visual Studio / Rider.\n\n## Getting Started\n\n### 1. Register the Services\n\nTo use the BlazorStateProvider in your application, register the services in your Program.cs file:\n\n```csharp\nusing BlazorStateProvider.Extensions;\n\npublic class Program\n{\n    public static void Main(string[] args)\n    {\n        var builder = WebAssemblyHostBuilder.CreateDefault(args);\n        builder.RootComponents.Add\u003cApp\u003e(\"#app\");\n\n        // Register BlazorStateProvider services\n        builder.Services.AddBlazorStateProvider();\n\n        await builder.Build().RunAsync();\n    }\n}\n```\n\n### 2. Inject and Use the State Provider\nYou can now inject the state Providers into your Blazor components.\n\n```csharp\n@page \"/example\"\n@inject IStateProvider StateProvider\n\n\u003ch3\u003eState Management Example\u003c/h3\u003e\n\n\u003cbutton @onclick=\"SaveState\"\u003eSave State\u003c/button\u003e\n\u003cbutton @onclick=\"LoadState\"\u003eLoad State\u003c/button\u003e\n\n@code {\n    private async Task SaveState()\n    {\n        await StateProvider.SetStateAsync(\"exampleKey\", \"Hello, World!\");\n    }\n\n    private async Task LoadState()\n    {\n        var value = await StateProvider.GetStateAsync\u003cstring\u003e(\"exampleKey\");\n        Console.WriteLine($\"Loaded State: {value}\");\n    }\n}\n```\n\n## API Reference\n\n### Interfaces\n\n- `IStateProvider`: The main interface for managing state in Blazor applications.\n- `ILocalStorageStateProvider`: Interface for managing state using local storage.\n- `ISessionStorageStateProvider`: Interface for managing state using session storage.\n\n### Methods\n\n- `SetStateAsync\u003cT\u003e(string key, T value)`: Sets the state value for the specified key.\n- `GetStateAsync\u003cT\u003e(string key)`: Gets the state value for the specified key.\n- `RemoveStateAsync(string key)`: Removes the state value for the specified key.\n- `ResetStateAsync()`: Resets the state by removing all stored values.\n- `Subscribe\u003cT\u003e(Action callback)`: Subscribes to state change notifications for the specified key.\n- `Unsubscribe\u003cT\u003e(Action callback)`: Unsubscribes from state change notifications for the specified key.\n\n## Example\nHere’s a simple example of how to use the BlazorStateProvider in your components:\n\n```csharp\n@page \"/example\"\n@inject ILocalStorageStateProvider LocalStorageProvider\n\n\u003ch3\u003eLocal Storage Example\u003c/h3\u003e\n\n\u003cbutton @onclick=\"SaveToLocalStorage\"\u003eSave to Local Storage\u003c/button\u003e\n\u003cbutton @onclick=\"LoadFromLocalStorage\"\u003eLoad from Local Storage\u003c/button\u003e\n\n@code {\n    private async Task SaveToLocalStorage()\n    {\n        await LocalStorageProvider.SetStateAsync(\"username\", \"JohnDoe\");\n    }\n\n    private async Task LoadFromLocalStorage()\n    {\n        var username = await LocalStorageProvider.GetStateAsync\u003cstring\u003e(\"username\");\n        Console.WriteLine($\"Loaded Username: {username}\");\n    }\n}\n```\n\n## Contributing\n\nContributions are welcome! If you find any issues or have suggestions for improvements, please submit an issue or a pull request.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaileshrijal%2Fblazorstateprovider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaileshrijal%2Fblazorstateprovider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaileshrijal%2Fblazorstateprovider/lists"}