Skip to content

Commit

Permalink
chore: multitenant store fixups (#653)
Browse files Browse the repository at this point in the history
multitenant store fixups
  • Loading branch information
AndrewTriesToCode authored Mar 19, 2023
1 parent 375add5 commit 79d9124
Show file tree
Hide file tree
Showing 52 changed files with 1,559 additions and 1,416 deletions.
2 changes: 1 addition & 1 deletion .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"prepareCmd": "./release.sh -f private -v ${nextRelease.version} -r \"${nextRelease.notes}\""
}],
["@semantic-release/git", {
"assets": ["Directory.Build.props", "*.md", "docs"],
"assets": ["src/Directory.Build.props", "*.md", "docs"],
"message": "chore: ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}]
]
Expand Down
2 changes: 1 addition & 1 deletion release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ do
done

# Update the Version property in Directory.Build.props:
sed -E -i 's|<Version>.*</Version>|<Version>'"${version}"'</Version>|g' Directory.Build.props
sed -E -i 's|<Version>.*</Version>|<Version>'"${version}"'</Version>|g' src/Directory.Build.props

# Update the version in readme and docs files with <span class="_version"> elements:
sed -E -i 's|<span class="_version">.*</span>|<span class="_version">'"${version}"'</span>|g' README.md docs/*.md
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props → src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageTags>finbuckle;multitenant;multitenancy;aspnet;aspnetcore;entityframework;entityframework-core;efcore</PackageTags>
<PackageIcon>finbuckle-128x128.png</PackageIcon>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>CS1591</NoWarn>
<!-- <NoWarn>CS1591</NoWarn>-->
</PropertyGroup>

<ItemGroup>
Expand Down
61 changes: 46 additions & 15 deletions src/Finbuckle.MultiTenant/Abstractions/IMultiTenantContext.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,54 @@
// Copyright Finbuckle LLC, Andrew White, and Contributors.
// Refer to the solution LICENSE file for more inforation.

namespace Finbuckle.MultiTenant
// ReSharper disable once CheckNamespace
namespace Finbuckle.MultiTenant;

/// <summary>
/// Non-generic interface for the multitenant context.
/// </summary>
public interface IMultiTenantContext
{
public interface IMultiTenantContext
{
ITenantInfo? TenantInfo { get; }
bool HasResolvedTenant => TenantInfo != null;
/// <summary>
/// Information about the tenant for this context.
/// </summary>
ITenantInfo? TenantInfo { get; }

/// <summary>
/// True if a non-null tenant has been resolved.
/// </summary>
bool HasResolvedTenant => TenantInfo != null;

StrategyInfo? StrategyInfo { get; }
}
/// <summary>
/// Information about the multitenant strategies for this context.
/// </summary>
StrategyInfo? StrategyInfo { get; }
}

public interface IMultiTenantContext<T>
where T : class, ITenantInfo, new()
{
T? TenantInfo { get; set; }
bool HasResolvedTenant => TenantInfo != null;
/// <summary>
/// Generic interface for the multitenant context.
/// </summary>
/// <typeparam name="T">The ITenantInfo implementation type.</typeparam>
public interface IMultiTenantContext<T>
where T : class, ITenantInfo, new()
{
/// <summary>
/// Information about the tenant for this context.
/// </summary>
T? TenantInfo { get; set; }
/// <summary>
/// Returns true if a non-null tenant has been resolved.
/// </summary>
bool HasResolvedTenant => TenantInfo != null;

/// <summary>
/// Information about the multitenant strategies for this context.
/// </summary>
StrategyInfo? StrategyInfo { get; set; }


StrategyInfo? StrategyInfo { get; set; }
StoreInfo<T>? StoreInfo { get; set; }
}
/// <summary>
/// Information about the multitenant store(s) for this context.
/// </summary>
StoreInfo<T>? StoreInfo { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Copyright Finbuckle LLC, Andrew White, and Contributors.
// Refer to the solution LICENSE file for more inforation.

namespace Finbuckle.MultiTenant
namespace Finbuckle.MultiTenant;

public interface IMultiTenantContextAccessor
{
public interface IMultiTenantContextAccessor
{
IMultiTenantContext? MultiTenantContext { get; set; }
}
IMultiTenantContext? MultiTenantContext { get; set; }
}

public interface IMultiTenantContextAccessor<T> where T : class, ITenantInfo, new()
{
IMultiTenantContext<T>? MultiTenantContext { get; set; }
}
public interface IMultiTenantContextAccessor<T> where T : class, ITenantInfo, new()
{
IMultiTenantContext<T>? MultiTenantContext { get; set; }
}
96 changes: 50 additions & 46 deletions src/Finbuckle.MultiTenant/Abstractions/IMultiTenantStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,57 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Finbuckle.MultiTenant
// ReSharper disable once CheckNamespace
namespace Finbuckle.MultiTenant;


/// <summary>
/// Interface definition for tenant stores.
/// </summary>
/// <typeparam name="TTenantInfo">The ITenantInfo implementation type.</typeparam>
public interface IMultiTenantStore<TTenantInfo> where TTenantInfo : class, ITenantInfo, new()
{
/// <summary>
/// Interface definition for tenant stores.
/// Try to add the TTenantInfo to the store.
/// </summary>
/// <param name="tenantInfo">New TTenantInfo instance to add.</param>
/// <returns>True if successfully added</returns>
Task<bool> TryAddAsync(TTenantInfo tenantInfo);

/// <summary>
/// Try to update the TTenantInfo in the store.
/// </summary>
/// <param name="tenantInfo">Existing TTenantInfo instance to update.</param>
/// <returns>True if successfully updated.</returns>
Task<bool> TryUpdateAsync(TTenantInfo tenantInfo);

/// <summary>
/// Try to remove the TTenantInfo from the store.
/// </summary>
/// <param name="identifier">Identifier for the tenant to remove. </param>
/// <returns>True if successfully removed</returns>
Task<bool> TryRemoveAsync(string identifier);

/// <summary>
/// Retrieve the TTenantInfo for a given identifier.
/// </summary>
/// <param name="identifier">Identifier for the tenant to retrieve.</param>
/// <returns>Returns TTenantInfo instance if found or null.</returns>
/// TODO make obsolete
Task<TTenantInfo?> TryGetByIdentifierAsync(string identifier);

/// <summary>
/// Retrieve the TTenantInfo for a given tenant Id.
/// </summary>
/// <param name="id">TenantId for the tenant to retrieve.</param>
/// <returns>Returns TTenantInfo instance if found or null.</returns>
/// TODO make obsolete
Task<TTenantInfo?> TryGetAsync(string id);


/// <summary>
/// Retrieve all the TTenantInfo's from the store.
/// </summary>
public interface IMultiTenantStore<TTenantInfo> where TTenantInfo : class, ITenantInfo, new()
{
/// <summary>
/// Try to add the TTenantInfo to the store.
/// </summary>
/// <param name="tenantInfo"></param>
/// <returns></returns>
Task<bool> TryAddAsync(TTenantInfo tenantInfo);

/// <summary>
/// Try to update the TTenantInfo in the store.
/// </summary>
/// <param name="tenantInfo"></param>
/// <returns></returns>
Task<bool> TryUpdateAsync(TTenantInfo tenantInfo);

/// <summary>
/// Try to remove the TTenantInfo from the store.
/// </summary>
/// <param name="tenantInfo"></param>
/// <returns></returns>
Task<bool> TryRemoveAsync(string tenantInfo);

/// <summary>
/// Retrieve the TTenantInfo for a given identifier.
/// </summary>
/// <param name="identifier"></param>
/// <returns></returns>
Task<TTenantInfo?> TryGetByIdentifierAsync(string identifier);

/// <summary>
/// Retrieve the TTenantInfo for a given tenant Id.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<TTenantInfo?> TryGetAsync(string id);


/// <summary>
/// Retrieve all the TTenantInfo's from the store.
/// </summary>
/// <returns></returns>
Task<IEnumerable<TTenantInfo>> GetAllAsync();
}
/// <returns>IEnumerable of all tenants in the store.</returns>
Task<IEnumerable<TTenantInfo>> GetAllAsync();
}
29 changes: 14 additions & 15 deletions src/Finbuckle.MultiTenant/Abstractions/IMultiTenantStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@

using System.Threading.Tasks;

namespace Finbuckle.MultiTenant
namespace Finbuckle.MultiTenant;

/// <summary>
/// The interface for determining the tenant idenfitider.
/// </summary>
public interface IMultiTenantStrategy
{
/// <summary>
/// The interface for determining the tenant idenfitider.
/// Method for implemenations to control how the identifier is determined.
/// </summary>
public interface IMultiTenantStrategy
{
/// <summary>
/// Method for implemenations to control how the identifier is determined.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
Task<string?> GetIdentifierAsync(object context);
/// <param name="context"></param>
/// <returns></returns>
Task<string?> GetIdentifierAsync(object context);

/// <summary>
/// Determines strategy execution order. Normally handled in the order registered.
/// </summary>
int Priority => 0;
}
/// <summary>
/// Determines strategy execution order. Normally handled in the order registered.
/// </summary>
int Priority => 0;
}
15 changes: 7 additions & 8 deletions src/Finbuckle.MultiTenant/Abstractions/ITenantInfo.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Copyright Finbuckle LLC, Andrew White, and Contributors.
// Refer to the solution LICENSE file for more inforation.

namespace Finbuckle.MultiTenant
namespace Finbuckle.MultiTenant;

public interface ITenantInfo
{
public interface ITenantInfo
{
string? Id { get; set; }
string? Identifier { get; set; }
string? Name { get; set; }
string? ConnectionString { get; set; }
}
string? Id { get; set; }
string? Identifier { get; set; }
string? Name { get; set; }
string? ConnectionString { get; set; }
}
23 changes: 11 additions & 12 deletions src/Finbuckle.MultiTenant/Abstractions/ITenantResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Finbuckle.MultiTenant
namespace Finbuckle.MultiTenant;

public interface ITenantResolver
{
public interface ITenantResolver
{
Task<IMultiTenantContext?> ResolveAsync(object context);
}
Task<IMultiTenantContext?> ResolveAsync(object context);
}

public interface ITenantResolver<T>
where T : class, ITenantInfo, new()
{
IEnumerable<IMultiTenantStrategy> Strategies { get; }
IEnumerable<IMultiTenantStore<T>> Stores { get; }
public interface ITenantResolver<T>
where T : class, ITenantInfo, new()
{
IEnumerable<IMultiTenantStrategy> Strategies { get; }
IEnumerable<IMultiTenantStore<T>> Stores { get; }

Task<IMultiTenantContext<T>?> ResolveAsync(object context);
}
Task<IMultiTenantContext<T>?> ResolveAsync(object context);
}
Loading

0 comments on commit 79d9124

Please sign in to comment.