public async Task <IDisposable> RemoveTenantShell(TenantIdentifier identifier) { TenantShell <TTenant> removed = null; if (!_cache.TryGetValue(identifier, out TenantShell <TTenant> result)) { // tenant hasn't yet been initialised.. so nothing to do.. return(null); } try { await _semaphore.WaitAsync(); // block restarting if a tenant intiialise in process or another restart in prcess. // tenant may have just been restarted on another thread and removed from cache, so check again. //Todo: make this more robust if TryRemove returns false for example.. var isRemoved = _cache.TryRemove(identifier, out removed); if (isRemoved) { foreach (var item in removed.Identifiers) { if (item.Equals(identifier)) { continue; } isRemoved = _cache.TryRemove(item, out TenantShell <TTenant> itemRemoved); } } // dispose after small delay to allow respoinse to be returned flowing back through the same pipeline. #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed return(removed); //Task.Delay(new TimeSpan(0, 0, 2)).ContinueWith((t) => //{ // removed?.Dispose(); //}); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } finally { _semaphore.Release(); } }
public bool TryGetValue(TenantDistinguisher key, out TenantShell <TTenant> value) { return(_mappings.TryGetValue(key, out value)); }
public TenantShell <TTenant> AddOrUpdate(TenantDistinguisher key, TenantShell <TTenant> addValue, Func <TenantDistinguisher, TenantShell <TTenant>, TenantShell <TTenant> > updateValueFactory) { return(_mappings.AddOrUpdate(key, addValue, updateValueFactory)); }
public bool TryRemove(TenantIdentifier key, out TenantShell <TTenant> value) { return(_mappings.TryRemove(key, out value)); }
public static Lazy <Task <ITenantContainerAdaptor> > GetOrAddContainer <TTenant>(this TenantShell <TTenant> tenantShell, Func <Task <ITenantContainerAdaptor> > containerAdaptorFactory) where TTenant : class { var result = tenantShell.Properties.GetOrAdd(nameof(TenantShellContainerExtensions), (a) => { // var factory = containerAdaptorFactory(); return(new Lazy <Task <ITenantContainerAdaptor> >(containerAdaptorFactory)); }) as Lazy <Task <ITenantContainerAdaptor> >; return(result); }
public static Lazy <Task <TenantContainerNancyBootstrapper <TTenant> > > GetOrAddNancyBootstrapper <TTenant>(this TenantShell <TTenant> tenantShell, Func <Task <TenantContainerNancyBootstrapper <TTenant> > > nancyBootstrapper) where TTenant : class { var result = tenantShell.Properties.GetOrAdd(nameof(TenantShellNancyExtensions), (a) => { // var factory = containerAdaptorFactory(); return(new Lazy <Task <TenantContainerNancyBootstrapper <TTenant> > >(nancyBootstrapper)); }) as Lazy <Task <TenantContainerNancyBootstrapper <TTenant> > >; return(result); }
public static Lazy <Task <ITenantContainerAdaptor> > GetOrAddContainer <TTenant>(this TenantShell <TTenant> tenantShell, Func <Task <ITenantContainerAdaptor> > containerAdaptorFactory) where TTenant : class { return(tenantShell.GetOrAddProperty(nameof(TenantShellContainerExtensions), (a) => { var newItem = new Lazy <Task <ITenantContainerAdaptor> >(containerAdaptorFactory); tenantShell.RegisterCallbackOnDispose(() => { if (newItem.IsValueCreated) { var result = newItem.Value.Result; result?.Dispose(); } }); return newItem; }) as Lazy <Task <ITenantContainerAdaptor> >); }
public static Lazy <Task <ITenantContainerAdaptor> > GetOrAddContainer <TTenant>(this TenantShell <TTenant> tenantShell, Func <Task <ITenantContainerAdaptor> > containerAdaptorFactory) where TTenant : class { return(tenantShell.Properties.GetOrAdd(nameof(TenantShellContainerExtensions), (a) => { return new Lazy <Task <ITenantContainerAdaptor> >(containerAdaptorFactory); }) as Lazy <Task <ITenantContainerAdaptor> >); }