Zonit.Extensions.Organizations 10.0.0-preview.26

This is a prerelease version of Zonit.Extensions.Organizations.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Zonit.Extensions.Organizations --version 10.0.0-preview.26
                    
NuGet\Install-Package Zonit.Extensions.Organizations -Version 10.0.0-preview.26
                    
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="Zonit.Extensions.Organizations" Version="10.0.0-preview.26" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zonit.Extensions.Organizations" Version="10.0.0-preview.26" />
                    
Directory.Packages.props
<PackageReference Include="Zonit.Extensions.Organizations" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Zonit.Extensions.Organizations --version 10.0.0-preview.26
                    
#r "nuget: Zonit.Extensions.Organizations, 10.0.0-preview.26"
                    
#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.
#:package Zonit.Extensions.Organizations@10.0.0-preview.26
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Zonit.Extensions.Organizations&version=10.0.0-preview.26&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Zonit.Extensions.Organizations&version=10.0.0-preview.26&prerelease
                    
Install as a Cake Tool

Zonit.Extensions.Organizations

Workspace (organization / tenant) context for Zonit applications: which organization the current user is working in, and which ones they can switch into. Framework-agnostic — no HttpContext, no middleware, no Blazor types. The ASP.NET Core middleware and the prerender → circuit bridge ship in Zonit.Extensions.Website.

NuGet Downloads

dotnet add package Zonit.Extensions.Organizations

What you get

  • IOrganizationSource — the one contract you implement: load the current workspace, list switchable organizations, perform a switch. Everything else is built on it.
  • IWorkspaceManager — per-scope state machine: Initialize(StateModel), InitializeAsync(ct), SwitchOrganizationAsync(id, ct), plus Workspace / Organizations / State and OnChange.
  • IWorkspaceProvider — read surface for UI and domain code: the active organization as the Organization value object, Organization.Empty when none is selected.

AddOrganizationsExtension() registers exactly three scoped services — IWorkspaceManager, IWorkspaceProvider and a NullOrganizationSource safety net — and nothing else.

Setup

In a Website host, register only your source: AddWebsite() already calls AddOrganizationsExtension() and UseWebsite<TApp>() installs the middleware.

builder.Services.AddScoped<IOrganizationSource, AcmeOrganizationSource>();
builder.Services.AddWebsite();

Anywhere else (console, worker, tests) wire it yourself and drive the manager once per scope:

services.AddScoped<IOrganizationSource, AcmeOrganizationSource>();
services.AddOrganizationsExtension();

await using var scope = provider.CreateAsyncScope();
var manager = scope.ServiceProvider.GetRequiredService<IWorkspaceManager>();
await manager.InitializeAsync(cancellationToken);

Use AddScoped, not TryAddScoped. The null source is registered with TryAddScoped; a TryAddScoped of your own after it is a silent no-op and you keep an empty workspace forever.

Implementing the source

public interface IOrganizationSource
{
    Task<WorkspaceModel> InitializeAsync(CancellationToken cancellationToken = default);
    Task<IReadOnlyCollection<OrganizationModel>?> GetOrganizationsAsync(CancellationToken cancellationToken = default);
    Task<WorkspaceModel?> SwitchOrganizationAsync(Guid organizationId, CancellationToken cancellationToken = default);
}

Three things the compiler will not tell you:

  1. InitializeAsync and GetOrganizationsAsync are started concurrently on the same scoped instance (Task.WhenAll). Inject IDbContextFactory<T>, not a shared DbContext — EF Core forbids overlapping operations on one context.
  2. null from SwitchOrganizationAsync means denied — this method is the authorization check. GetOrganizationsAsync returning null means "unknown"; return [] for "member of nothing".
  3. OrganizationModel.Id must be non-empty and Name non-blank and ≤ 60 graphemes, or the projection to the Organization value object degrades silently (empty organization / empty or truncated title). It never throws.

In a Website host the whole snapshot — the active workspace and every organization you return — is serialized into the prerendered HTML, so do not fill invoice fields (Email, TaxIdentification, address) unless the page needs them.

Reading the workspace

@inject IWorkspaceProvider Workspace

@if (Workspace.Organization.HasValue)
{
    <p>@Workspace.Organization.Name — @Workspace.Organization.Id</p>
}

Organization is a readonly struct: test HasValue, never != null. Pages deriving from PageBase / PageViewBase<T> already expose Workspace as a protected property.

Switching organization

if (!await manager.SwitchOrganizationAsync(organizationId, cancellationToken))
{
    // Denied — the previously selected organization is untouched and no OnChange fired.
}

A granted switch replaces the workspace, back-fills the organization list if the scope had none, and raises OnChange, which IWorkspaceProvider and ExtensionsBase-derived components observe.

Authorization is elsewhere

WorkspaceModel.Permissions / Roles are transported but never read by the framework. Authorization runs off the Identity produced by Zonit.Extensions.Auth ([RequirePermission], IAuthorizationService, <AuthorizeView>). Pure tenancy lives here.

Migration to 10.0.0-preview.10

Removed public types — there is no drop-in replacement; the framework only ever needs IOrganizationSource:

Removed Notes
IOrganizationProvider GetOrganizationAsync / GetUserOrganizationAsync / GetUserOrganizationsAsync belong in your own data layer
IOrganizationManager single-method (GetAsync) lookup contract, unused by the framework
IOrganizationEntity unused marker; put Guid OrganizationId on your entity and filter with IWorkspaceProvider.Organization
Zonit.Extensions.Organizations.Entities.Organization use the Zonit.Extensions.Organization value object or your own entity
<ZonitOrganizationsExtension /> replaced by <WebsiteHydrator /> (Zonit.Extensions.Website), placed once in App.razor

Behaviour changes:

  • IWorkspaceManager.SwitchOrganizationAsync returns Task<bool> instead of Task. Source-compatible for a plain await, binary-breaking (recompile), source-breaking for anyone implementing the interface.
  • A denied switch is now a no-op. It used to clear the workspace, logging the user out of an organization they did have access to; it now returns false and leaves the selection alone.
  • A switch on a scope that was never initialized is no longer ignored — the source is called, so SwitchOrganizationAsync may arrive without a preceding InitializeAsync on the same scope.
  • Malformed source data no longer throws ArgumentException from IWorkspaceProvider.Organization: Guid.EmptyOrganization.Empty, blank name → Title.Empty, over-long name → truncated at 60 graphemes. Read IWorkspaceManager.Workspace?.Organization for the verbatim values.

Earlier versions also exposed IsPermission(string) / IsRole(string) with hard-coded "Developer" / "All" bypasses. That is gone; see Zonit.Extensions.Auth.

License

MIT.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Zonit.Extensions.Organizations:

Package Downloads
Zonit.Extensions.Website

ASP.NET Core and Blazor web extensions providing base components (PageBase, PageEditBase, PageViewBase), navigation services, breadcrumbs management, toast notifications, cookie handling, and data protection utilities for building modern web applications.

Zonit.Services.Dashboard

Package Description

Zonit.Services.Manager

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.0.0-preview.27 51 8/17/2026
10.0.0-preview.26 59 8/14/2026
10.0.0-preview.25 52 8/14/2026
10.0.0-preview.24 49 8/12/2026
10.0.0-preview.23 59 8/11/2026
10.0.0-preview.22 49 8/11/2026
10.0.0-preview.21 55 8/11/2026
10.0.0-preview.20 54 8/10/2026
10.0.0-preview.19 58 8/10/2026
10.0.0-preview.18 56 8/9/2026
10.0.0-preview.17 65 8/9/2026
10.0.0-preview.16 62 8/9/2026
10.0.0-preview.15 59 8/7/2026
10.0.0-preview.14 57 8/6/2026
10.0.0-preview.13 58 8/6/2026
10.0.0-preview.12 47 8/6/2026
10.0.0-preview.11 80 8/4/2026
10.0.0-preview.10 67 8/3/2026
10.0.0-preview.9 71 5/16/2026
0.1.52 152 1/15/2026
Loading failed