public ILifetimeScope GetScope(CreationContext context) { foreach (var additionalArgument in context.AdditionalArguments.Values) { if (additionalArgument is ServiceStub) { var serviceStub = additionalArgument as ServiceStub; if (_createdScopes.ContainsKey(serviceStub)) { return(_createdScopes[serviceStub]); } else { var scope = new DefaultLifetimeScope(); _createdScopes[serviceStub] = scope; serviceStub.Disposing += RemoveScope; return(scope); } } } throw new InvalidOperationException("This was not used as intented, I am expecting a servicestub as a provided argument"); }
/// <summary> /// Gets the scope of the resolving object -> if an instance for <see cref="TScope"/> is already created return this, otherwise create a new instance /// </summary> /// <param name="context">The <see cref="CreationContext"/></param> /// <returns>The existing instance or a new instance if none exists</returns> /// <exception cref="ArgumentException">If no additional arguments are given</exception> public ILifetimeScope GetScope(CreationContext context) { if (!context.HasAdditionalArguments) { throw new ArgumentException("No additional arguments given."); } var keyValuePair = context.AdditionalArguments.ToList().First(); if (!(keyValuePair.Value is TScope scope)) { throw new ArgumentException($"First additional argument is not of type {typeof(TScope)} (Type: {context.AdditionalArguments[0].GetType()})."); } lock (_instancesLockObject) { if (_instances.TryGetValue(scope, out ILifetimeScope lifetimeScope)) { return(lifetimeScope); } lifetimeScope = new DefaultLifetimeScope(); _instances.Add(scope, lifetimeScope); return(lifetimeScope); } }
public void ClearScope() { var newScope = new DefaultLifetimeScope(); var oldScope = Interlocked.Exchange(ref scope, newScope); oldScope.Dispose(); }
public ILifetimeScope GetScope(CreationContext context) { var messageContext = MessageContext.Current; if (messageContext == null) { throw new InvalidOperationException(string.Format("Attempted to resolve {0} outside of Rebus message context!", context.RequestedType)); } var items = messageContext.TransactionContext.Items; object lifetimeScope; if (items.TryGetValue(LifestimeScopeItemKey, out lifetimeScope)) { return((ILifetimeScope)lifetimeScope); } var defaultLifetimeScope = new DefaultLifetimeScope(); items[LifestimeScopeItemKey] = defaultLifetimeScope; messageContext.TransactionContext.OnDisposed(() => defaultLifetimeScope.Dispose()); return(defaultLifetimeScope); }
private void RemoveScope(ServiceStub sender) { sender.Disposing -= RemoveScope; DefaultLifetimeScope scope = _createdScopes[sender]; _createdScopes.Remove(sender); scope.Dispose(); }
public MsLifetimeScope(IWindsorContainer container) { Container = container; WindsorLifeTimeScope = new DefaultLifetimeScope(); _children = new List <MsLifetimeScope>(); _resolvedInstances = new List <object>(); _disposed = new ThreadSafeFlag(); }
private static ILifetimeScope GetScope(HttpContext context, bool createIfNotPresent) { var candidates = (ILifetimeScope)context.Items[key]; if (candidates == null && createIfNotPresent) { candidates = new DefaultLifetimeScope(new ScopeCache()); context.Items[key] = candidates; } return(candidates); }
private static ILifetimeScope GetScope(HttpSessionState session, bool createIfNotPresent) { var lifetimeScope = (ILifetimeScope)session[key]; if (lifetimeScope == null && createIfNotPresent) { lifetimeScope = new DefaultLifetimeScope(new ScopeCache(), null); session[key] = lifetimeScope; return(lifetimeScope); } return(lifetimeScope); }
private static ILifetimeScope GetOrCreateSessionScope(HttpSessionStateBase session) { var scope = (ILifetimeScope)session[lifetimeScopeKey]; if (scope != null) { return(scope); } scope = new DefaultLifetimeScope(); session[lifetimeScopeKey] = scope; return(scope); }
public ILifetimeScope GetScope(CreationContext context) { if (!MessageContext.HasCurrent) { return(null); } return(scopes.GetOrAdd(MessageContext.GetCurrent(), messageContext => { var scope = new DefaultLifetimeScope(new ScopeCache()); messageContext.Disposed += scope.Dispose; return scope; })); }
public override async Task Invoke(IOwinContext context) { ILifetimeScope lifetimeScope = new DefaultLifetimeScope(); context.Environment[EnvironmentKey] = lifetimeScope; try { await this.Next.Invoke(context); } finally { context.Environment.Remove(EnvironmentKey); lifetimeScope.Dispose(); } }
private static ILifetimeScope GetScope(IOwinRequestScopeContext context, bool createIfNotPresent) { ILifetimeScope candidates = null; if (context.Items.ContainsKey(c_key)) { candidates = (ILifetimeScope)context.Items[c_key]; } else if (createIfNotPresent) { candidates = new DefaultLifetimeScope(new ScopeCache()); context.Items[c_key] = candidates; } return(candidates); }
public ILifetimeScope GetScope(CreationContext context) { var current = HttpContext.Current; if (current == null) { throw new InvalidOperationException("HttpContext.Current is null. PerWebSessionLifestyle can only be used in ASP.Net"); } var lifetimeScope = (ILifetimeScope)current.Session[Key]; if (lifetimeScope == null) { lifetimeScope = new DefaultLifetimeScope(new ScopeCache()); current.Session[Key] = lifetimeScope; return(lifetimeScope); } return(lifetimeScope); }
public override async Task Invoke(IOwinContext context) { ILifetimeScope lifetimeScope = new DefaultLifetimeScope(); try { context.Environment[EnvironmentKey] = lifetimeScope; await Next.Invoke(context); } catch (Exception ex) { } finally { context.Environment.Remove(EnvironmentKey); lifetimeScope.Dispose(); } }
private static ILifetimeScope GetOrCreateScope(bool createIfNotPresent) { var context = HttpContext.Current; if (context == null) { return(null); } var candidates = (ILifetimeScope)context.Items[Key]; if (candidates == null && createIfNotPresent) { candidates = new DefaultLifetimeScope(new ScopeCache()); context.Items[Key] = candidates; } return(candidates); }
public ILifetimeScope GetScope(CreationContext context) { var httpContext = System.Web.HttpContext.Current; if (httpContext == null) { return(null); } if (!httpContext.Items.Contains(typeof(PerRequestScopeAccessor))) { lock (httpContext.Items.SyncRoot) { if (!httpContext.Items.Contains(typeof(PerRequestScopeAccessor))) { var scope = new DefaultLifetimeScope(new ScopeCache()); httpContext.Items[typeof(PerRequestScopeAccessor)] = scope; httpContext.DisposeOnPipelineCompleted(scope); return(scope); } } } return((ILifetimeScope)httpContext.Items[typeof(PerRequestScopeAccessor)]); }
private static ILifetimeScope GetOrCreateScope(bool createIfNotPresent) { var context = FuncHttpCache?.Invoke(noInput); if (context == null) { return(null); } // var context = HttpContext.Current; // if (context == null) // { // return null; // } var candidates = (ILifetimeScope)context[Key]; if (candidates == null && createIfNotPresent) { candidates = new DefaultLifetimeScope(new ScopeCache()); context[Key] = candidates; } return(candidates); }
public static void ResetScope() { scope = new DefaultLifetimeScope(); }
public WcfSessionScopeHolder(DefaultLifetimeScope scope) { this.scope = scope; }