Skip to content

Commit

Permalink
feat: add nongeneric IMultiTenantContext for flexibility
Browse files Browse the repository at this point in the history
  • Loading branch information
kakone authored Jan 21, 2023
1 parent 688d09b commit b3a198f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/Finbuckle.MultiTenant/Abstractions/IMultiTenantContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

namespace Finbuckle.MultiTenant
{
public interface IMultiTenantContext
{
ITenantInfo? TenantInfo { get; }
StrategyInfo? StrategyInfo { get; }
}

public interface IMultiTenantContext<T>
where T : class, ITenantInfo, new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Finbuckle.MultiTenant
{
public interface IMultiTenantContextAccessor
{
object? MultiTenantContext { get; set; }
IMultiTenantContext? MultiTenantContext { get; set; }
}

public interface IMultiTenantContextAccessor<T> where T : class, ITenantInfo, new()
Expand Down
2 changes: 1 addition & 1 deletion src/Finbuckle.MultiTenant/Abstractions/ITenantResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Finbuckle.MultiTenant
{
public interface ITenantResolver
{
Task<object?> ResolveAsync(object context);
Task<IMultiTenantContext?> ResolveAsync(object context);
}

public interface ITenantResolver<T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public IMultiTenantContext<T>? MultiTenantContext
}
}

object? IMultiTenantContextAccessor.MultiTenantContext
IMultiTenantContext? IMultiTenantContextAccessor.MultiTenantContext
{
get => MultiTenantContext;
get => MultiTenantContext as IMultiTenantContext;
set => MultiTenantContext = value as IMultiTenantContext<T> ?? MultiTenantContext;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/Finbuckle.MultiTenant/MultiTenantContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ namespace Finbuckle.MultiTenant
/// <summary>
/// Contains information for the multitenant tenant, store, and strategy.
/// </summary>
public class MultiTenantContext<T> : IMultiTenantContext<T>
public class MultiTenantContext<T> : IMultiTenantContext<T>, IMultiTenantContext
where T : class, ITenantInfo, new()
{
public T? TenantInfo { get; set; }
public StrategyInfo? StrategyInfo { get; set; }
public StoreInfo<T>? StoreInfo { get; set; }

ITenantInfo? IMultiTenantContext.TenantInfo => TenantInfo;
}
}
5 changes: 2 additions & 3 deletions src/Finbuckle.MultiTenant/TenantResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ await options.CurrentValue.Events.OnTenantResolved(new TenantResolvedContext { C
return result;
}

async Task<object?> ITenantResolver.ResolveAsync(object context)
async Task<IMultiTenantContext?> ITenantResolver.ResolveAsync(object context)
{
var multiTenantContext = await ResolveAsync(context);
return multiTenantContext;
return (await ResolveAsync(context)) as IMultiTenantContext;
}
}
}

0 comments on commit b3a198f

Please sign in to comment.