Ejemplo n.º 1
0
        private static ILifetimeScope FromHttpContext()
        {
            if (HttpContext.Current != null)
            {
                var scope = DisposableHttpContext.Current["scope"] as ILifetimeScope;
                if (scope == null)
                {
                    scope = ToHttpContext();
                }
                else
                {
                    scope = new LifeTimeScopeProxy(scope);
                    try
                    {
                        scope.Resolve <IDbManager>();
                    }
                    catch (ObjectDisposedException e)
                    {
                        Logger.Error("FromHttpContext ObjectDisposedException", e);
                        scope = ToHttpContext();
                    }
                }

                return(scope);
            }

            return(Builder.BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag));
        }
Ejemplo n.º 2
0
        private static ILifetimeScope ToHttpContext()
        {
            var scope = Builder.BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag);
            var proxy = new LifeTimeScopeProxy(scope);

            DisposableHttpContext.Current["scope"] = scope;
            return(proxy);
        }