Default Tenant ID Provider (Session/DefaultCurrentTenantId.cs)

silky · framework/src/Silky.Core/Runtime/Session/DefaultCurrentTenantId.cs · csharp · MIT
infra, lang:csharp, tag:multitenancy, tag:session, tag:context

Manages the current tenant identifier within a scoped session. Use this to implement multi-tenancy by tracking and retrieving the active tenant context.

// Source: https://github.com/liuhll/silky | License: MIT | Copyright 2019 liuhongliang
// Provided via justclaw.it.com; keep this notice with the code.
using Silky.Core.DependencyInjection;

namespace Silky.Core.Runtime.Session;

public class DefaultCurrentTenantId : ICurrentTenantId, IScopedDependency
{
    private object? _tenantId;
    private bool isSetTenantId = false;

    public object? TenantId
    {
        get
        {
            if (isSetTenantId)
            {
                return _tenantId;
            }

            if (NullSession.Instance.TenantId != null)
            {
                return NullSession.Instance.TenantId;
            }

            return null;
        }
    }

    public void SetTenantId(object? tenantId)
    {
        isSetTenantId = true;
        _

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key