Skip to content

Commit

Permalink
Merge pull request #40 from marcwittke/hotfix/3.2.10
Browse files Browse the repository at this point in the history
Hotfix/3.2.10
  • Loading branch information
marcwittke committed Jul 11, 2018
2 parents 857e4b6 + d44fcf0 commit 7c56ce1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
13 changes: 8 additions & 5 deletions src/Backend.Fx.Bootstrapping/SimpleInjectorCompositionRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,15 @@ public IScope BeginScope(IIdentity identity, TenantId tenantId)
return scope;
}

/// <summary>
/// This should never be used in production code
/// </summary>
public Scope GetCurrentScopeForTestsOnly()
public IScope GetCurrentScope()
{
return ScopedLifestyle.GetCurrentScope(Container);
var scope = ScopedLifestyle.GetCurrentScope(Container);
if (scope == null)
{
return null;
}

return new SimpleInjectorScope(scope, scope.GetInstance<ICurrentTHolder<IIdentity>>().Current, scope.GetInstance<ICurrentTHolder<TenantId>>().Current);
}
#endregion

Expand Down
1 change: 1 addition & 0 deletions src/Backend.Fx.EfCorePersistence/TenantManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ protected override void SaveTenant(Tenant tenant)
existingTenant.IsDemoTenant = tenant.IsDemoTenant;
existingTenant.Name = tenant.Name;
existingTenant.Description = tenant.Description;
existingTenant.UriMatchingExpression = tenant.UriMatchingExpression;
}

if (tenant.IsDefault)
Expand Down
16 changes: 8 additions & 8 deletions src/Backend.Fx/Environment/MultiTenancy/ITenantManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public interface ITenantManager
Tenant GetTenant(TenantId id);
void EnsureTenantIsInitialized(TenantId tenantId);
Tenant FindTenant(TenantId tenantId);
TenantId CreateDemonstrationTenant(string name, string description, bool isDefault, CultureInfo defaultCultureInfo);
TenantId CreateProductionTenant(string name, string description, bool isDefault, CultureInfo defaultCultureInfo);
TenantId CreateDemonstrationTenant(string name, string description, bool isDefault, CultureInfo defaultCultureInfo, string uriMatchingExpression = null);
TenantId CreateProductionTenant(string name, string description, bool isDefault, CultureInfo defaultCultureInfo, string uriMatchingExpression = null);
TenantId GetDefaultTenantId();
}

Expand All @@ -36,21 +36,21 @@ protected TenantManager(ITenantInitializer tenantInitializer)
this.tenantInitializer = tenantInitializer;
}

public TenantId CreateDemonstrationTenant(string name, string description, bool isDefault, CultureInfo defaultCultureInfo)
public TenantId CreateDemonstrationTenant(string name, string description, bool isDefault, CultureInfo defaultCultureInfo, string uriMatchingExpression = null)
{
lock (syncLock)
{
Logger.Info($"Creating demonstration tenant: {name}");
return CreateTenant(name, description, true, isDefault, defaultCultureInfo);
return CreateTenant(name, description, true, isDefault, defaultCultureInfo, uriMatchingExpression);
}
}

public TenantId CreateProductionTenant(string name, string description, bool isDefault, CultureInfo defaultCultureInfo)
public TenantId CreateProductionTenant(string name, string description, bool isDefault, CultureInfo defaultCultureInfo, string uriMatchingExpression = null)
{
Logger.Info($"Creating production tenant: {name}");
lock (syncLock)
{
return CreateTenant(name, description, false, isDefault, defaultCultureInfo);
return CreateTenant(name, description, false, isDefault, defaultCultureInfo, uriMatchingExpression);
}
}

Expand Down Expand Up @@ -122,7 +122,7 @@ public void EnsureTenantIsInitialized(TenantId tenantId)

public abstract Tenant FindTenant(TenantId tenantId);

private TenantId CreateTenant([NotNull] string name, string description, bool isDemo, bool isDefault, CultureInfo defaultCultureInfo)
private TenantId CreateTenant([NotNull] string name, string description, bool isDemo, bool isDefault, CultureInfo defaultCultureInfo, string uriMatchingExpression)
{
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value cannot be null or whitespace.", nameof(name));

Expand All @@ -131,7 +131,7 @@ private TenantId CreateTenant([NotNull] string name, string description, bool is
throw new ArgumentException($"There is already a tenant named {name}");
}

Tenant tenant = new Tenant(name, description, isDemo, defaultCultureInfo) { State = TenantState.Created, IsDefault = isDefault };
Tenant tenant = new Tenant(name, description, isDemo, defaultCultureInfo) { State = TenantState.Created, IsDefault = isDefault, UriMatchingExpression = uriMatchingExpression};
SaveTenant(tenant);
return new TenantId(tenant.Id);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Backend.Fx/Patterns/DependencyInjection/IScopeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ public interface IScopeManager
/// the scope after finalization.
/// </summary>
IScope BeginScope(IIdentity identity, TenantId tenantId);

IScope GetCurrentScope();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void ThrowsWhenScopedInstanceIsRequestedOutsideScope()
{
Assert.Throws<ActivationException>(() => sut.GetInstance<IClock>());
Assert.Throws<ActivationException>(() => sut.GetInstance(typeof(IClock)));
Assert.Null(sut.GetCurrentScopeForTestsOnly());
Assert.Null(sut.GetCurrentScope());

using (var scope = sut.BeginScope(new SystemIdentity(), new TenantId(null)))
{
Expand All @@ -202,17 +202,14 @@ public void ThrowsWhenScopedInstanceIsRequestedOutsideScope()
Assert.Equal(sutClock, scopeClock);
}


Assert.Null(sut.GetCurrentScopeForTestsOnly());
Assert.Null(sut.GetCurrentScope());
Assert.Throws<ActivationException>(() => sut.GetInstance<IClock>());
Assert.Throws<ActivationException>(() => sut.GetInstance(typeof(IClock)));
}

[Fact]
public void CanProvideEventHandlers()
{


using (sut.BeginScope(new SystemIdentity(), new TenantId(1)))
{
var handlers = sut.GetAllEventHandlers<ADomainEvent>().ToArray();
Expand Down

0 comments on commit 7c56ce1

Please sign in to comment.