예제 #1
0
 public void EjectAll()
 {
     if (HttpContextLifecycle.HasContext())
     {
         _http.EjectAll();
     }
     _nonHttp.EjectAll();
 }
 public void Init(HttpApplication context)
 {
     context.BeginRequest += (sender, e) => StructuremapMvc.StructureMapDependencyScope.CreateNestedContainer();
     context.EndRequest   += (sender, e) => {
         HttpContextLifecycle.DisposeAndClearAll();
         StructuremapMvc.StructureMapDependencyScope.DisposeNestedContainer();
     };
 }
예제 #3
0
        protected virtual IDictionary findHttpDictionary()
        {
            if (!HttpContextLifecycle.HasContext())
            {
                throw new StructureMapException(309);
            }

            return(HttpContext.Current.Items);
        }
예제 #4
0
        public void Should_throw_when_context_is_not_available()
        {
            // Arrange
            var lifecycle = new HttpContextLifecycle();

            HttpContextLifecycle.HasContextResolver = () => false;

            // Act & assert
            Assert.Throws <InvalidOperationException>(() => lifecycle.FindCache());
        }
예제 #5
0
        private void OnContextOnEndRequest(object sender, EventArgs e)
        {
            foreach (var task in
                     StructuremapMvc.StructureMapDependencyScope.CurrentNestedContainer.GetAllInstances <IRunAfterEachRequest>())
            {
                task.Execute();
            }

            HttpContextLifecycle.DisposeAndClearAll();
            StructuremapMvc.StructureMapDependencyScope.DisposeNestedContainer();
        }
 public void Init(HttpApplication context)
 {
     context.BeginRequest += (sender, e) => StructuremapMvc.StructureMapDependencyScope.CreateNestedContainer();
     context.EndRequest   += (sender, e) =>
     {
         var unit = DependencyResolver.Current.GetService <IUnitOfWork>();
         unit.Commit();
         HttpContextLifecycle.DisposeAndClearAll();
         StructuremapMvc.StructureMapDependencyScope.DisposeNestedContainer();
     };
 }
예제 #7
0
        public void Should_return_false_when_not_available()
        {
            // Arrange
            new HttpContextLifecycle();             // Will reset to original state

            // Act
            var result = HttpContextLifecycle.HasContext();

            // Assert
            Assert.That(result, Is.False);
        }
예제 #8
0
 public void Init(HttpApplication context)
 {
     context.BeginRequest += (sender, e) =>
     {
         StructuremapMvc.StructureMapDependencyScope.CreateNestedContainer();
         var serviceLocatorProvider = new ServiceLocatorProvider(() => StructuremapMvc.StructureMapDependencyScope);
         StructuremapMvc.StructureMapDependencyScope.CurrentNestedContainer.Configure(cfg => cfg.For <ServiceLocatorProvider>().Use(serviceLocatorProvider));
     };
     context.EndRequest += (sender, e) => {
         HttpContextLifecycle.DisposeAndClearAll();
         StructuremapMvc.StructureMapDependencyScope.DisposeNestedContainer();
     };
 }
예제 #9
0
        public void Should_try_to_get_cache_from_context_when_context_is_available()
        {
            // Arrange
            var lifecycle = new HttpContextLifecycle();

            HttpContextLifecycle.HasContextResolver = () => true;

            // Act
            var exception = Assert.Throws <NullReferenceException>(() => lifecycle.FindCache());

            // Assert
            Assert.That(exception.Message, Is.EqualTo("Object reference not set to an instance of an object."));
        }
예제 #10
0
 /// <summary>
 ///
 /// </summary>
 public static void ApplicationEndRequest()
 {
     try
     {
         foreach (var task in ContainerManager.Container.GetAllInstances <IRunAfterEachRequest>())
         {
             task.Execute();
         }
     }
     catch (Exception)
     {
         HttpContextLifecycle.DisposeAndClearAll();
     }
 }
예제 #11
0
 protected void Application_EndRequest(object sender, EventArgs e)
 {
     try
     {
         foreach (var task in ProjectObjectFactory.Container.GetAllInstances <IRunAfterEachRequest>())
         {
             task.Execute();
         }
     }
     catch (Exception)
     {
         HttpContextLifecycle.DisposeAndClearAll();
     }
 }
예제 #12
0
 public void Init(HttpApplication context)
 {
     context.BeginRequest += (sender, e) => LocatorStartup.Locator.CreateNestedContainer();
     context.EndRequest   += (sender, e) =>
     {
         try
         {
             HttpContextLifecycle.DisposeAndClearAll();
             LocatorStartup.Locator.DisposeNestedContainer();
         }
         catch (InvalidOperationException)
         {
             // Catch HttpContextLifecycle.DisposeAndClearAll(); issues
         }
     };
 }
예제 #13
0
 public void Init(HttpApplication context)
 {
     try
     {
         context.BeginRequest += (sender, e) => StructuremapMvc.StructureMapDependencyScope.CreateNestedContainer();
         context.EndRequest   += (sender, e) =>
         {
             HttpContextLifecycle.DisposeAndClearAll();
             StructuremapMvc.StructureMapDependencyScope.DisposeNestedContainer();
         };
     }
     catch (Exception e)
     {
         Commons.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
     }
 }
예제 #14
0
        public void Should_return_new_cache_when_context_is_available()
        {
            // Arrange
            var dictionary = new Dictionary <object, object>();
            var lifecycle  = new HttpContextLifecycle();

            HttpContextLifecycle.HasContextResolver = () => true;
            HttpContextLifecycle.DictionaryResolver = () => dictionary;

            // Act
            var result = lifecycle.FindCache() as ObjectCache;

            // Assert
            Assert.That(result, Is.Not.Null);
            Assert.That(result.Count, Is.EqualTo(0));
        }
예제 #15
0
        void WebApiApplication_EndRequest(object sender, EventArgs e)
        {
            using (IUnitOfWork unitOfWork = StructureMap.ObjectFactory.GetInstance <IUnitOfWork>())
            {
                try
                {
                    unitOfWork.Commit();
                }
                catch (Exception)
                {
                    unitOfWork.Rollback();
                }
            }

            HttpContextLifecycle.DisposeAndClearAll();
        }
 public void Init(HttpApplication context)
 {
     context.BeginRequest += (sender, e) =>
     {
         StructuremapMvc.StructureMapDependencyScope.CreateNestedContainer();
         foreach (var task in StructuremapMvc.StructureMapDependencyScope.CurrentNestedContainer.GetAllInstances <IRunOnEachRequest>())
         {
             task.Execute();
         }
     };
     context.Error += (sender, e) =>
     {
         if (StructuremapMvc.StructureMapDependencyScope.CurrentNestedContainer != null)
         {
             foreach (var task in StructuremapMvc.StructureMapDependencyScope.CurrentNestedContainer
                      .GetAllInstances <IRunOnError>())
             {
                 task.Execute();
             }
         }
         else
         {
             StructuremapMvc.StructureMapDependencyScope.CreateNestedContainer();
             foreach (var task in StructuremapMvc.StructureMapDependencyScope.CurrentNestedContainer
                      .GetAllInstances <IRunOnError>())
             {
                 task.Execute();
             }
             HttpContextLifecycle.DisposeAndClearAll();
             StructuremapMvc.StructureMapDependencyScope.DisposeNestedContainer();
         }
     };
     context.EndRequest += (sender, e) => {
         try
         {
             foreach (var task in StructuremapMvc.StructureMapDependencyScope.CurrentNestedContainer.GetAllInstances <IRunAfterEachRequest>())
             {
                 task.Execute();
             }
         }
         finally
         {
             HttpContextLifecycle.DisposeAndClearAll();
             StructuremapMvc.StructureMapDependencyScope.DisposeNestedContainer();
         }
     };
 }
예제 #17
0
        public void Application_EndRequest(Object sender, EventArgs e)
        {
            try
            {
                foreach (var task in IoC.StructureMapResolver.CurrentNestedContainer.GetAllInstances <IRunAfterEachRequest>())
                {
                    task.Execute();
                }
            }
            finally
            {
                HttpContextLifecycle.DisposeAndClearAll();
                IoC.StructureMapResolver.DisposeNestedContainer();
            }

            DataContext.DisposeCurrent();
        }
예제 #18
0
        public void Should_return_existing_cache_when_context_is_available()
        {
            // Arrange
            var cache = new ObjectCache();

            cache.Set(Guid.NewGuid(), new object());

            var dictionary = new Dictionary <object, object>();

            dictionary.Add(HttpContextLifecycle.CacheKey, cache);

            var lifecycle = new HttpContextLifecycle();

            HttpContextLifecycle.HasContextResolver = () => true;
            HttpContextLifecycle.DictionaryResolver = () => dictionary;

            // Act
            var result = lifecycle.FindCache() as ObjectCache;

            // Assert
            Assert.That(result, Is.EqualTo(cache));
            Assert.That(result.Count, Is.EqualTo(1));
        }
예제 #19
0
        public void Init(HttpApplication context)
        {
            context.BeginRequest += (sender, e) =>
            {
                StructuremapMvc.StructureMapDependencyScope.CreateNestedContainer();
                var transactionManager = StructuremapMvc.StructureMapDependencyScope.GetInstance <ITransactionManager>();
                //lazy mode, no need start tx;
                LogMessage("BeginRequest: " + transactionManager.GetHashCode());
            };
            context.EndRequest += (sender, e) =>
            {
                HttpContextLifecycle.DisposeAndClearAll();
                StructuremapMvc.StructureMapDependencyScope.DisposeNestedContainer();
                LogMessage("EndRequest");
            };

            context.Error += (sender, args) =>
            {
                //not work for webapi, use WebApiTransactionFilter
                var transactionManager = StructuremapMvc.StructureMapDependencyScope.GetInstance <ITransactionManager>();
                transactionManager.Cancel();
                LogMessage("Request Ex: transactionManager.Cancel()");
            };
        }
예제 #20
0
 public IObjectCache FindCache()
 {
     return(HttpContextLifecycle.HasContext()
                ? _http.FindCache()
                : _nonHttp.FindCache());
 }
예제 #21
0
 public void cleanup()
 {
     // SAMPLE: clean-up-http-context
     HttpContextLifecycle.DisposeAndClearAll();
     // ENDSAMPLE
 }
 public void OnResultExecuted(ResultExecutedContext filterContext)
 {
     HttpContextLifecycle.DisposeAndClearAll();
 }
예제 #23
0
 public void HandleIncomingRequestProcessed()
 {
     HttpContextLifecycle.DisposeAndClearAll();
 }
예제 #24
0
 private static void ShutDown()
 {
     NHibernateContext.EndTransactions();
     HttpContextLifecycle.DisposeAndClearAll();
     StructuremapConfig.StructureMapResolver.DisposeNestedContainer();
 }
예제 #25
0
 /// <summary>
 /// Remove and dispose all objects scoped by HttpContext.  Call this method at the *end* of an Http request to clean up resources
 /// </summary>
 public static void ReleaseAndDisposeAllHttpScopedObjects()
 {
     HttpContextLifecycle.DisposeAndClearAll();
 }
 private void Application_EndRequest(object sender, EventArgs e)
 {
     //تخریب تمام اشیا ساخته شده توسط استراکچرمپ و برگشت منابع در صورتی که طول عمر شی براساس درخواست باشد
     HttpContextLifecycle.DisposeAndClearAll();
 }
 /// <summary>
 /// Application request end hook.
 /// </summary>
 protected void Application_EndRequest()
 {
     HttpContextLifecycle.DisposeAndClearAll();
 }
 public HybridHttpContextLifecycle()
 {
     _http    = new HttpContextLifecycle();
     _nonHttp = new ThreadLocalStorageLifecycle();
 }
예제 #29
0
 public static void HttpContextDisposeAndClearAll()
 {
     HttpContextLifecycle.DisposeAndClearAll();
 }
예제 #30
0
 protected void Application_EndRequest(object sender, EventArgs e)
 {
     HttpContextLifecycle.DisposeAndClearAll();
 }
 public HybridHttpContextLifecycle()
 {
     _http = new HttpContextLifecycle();
     _nonHttp = new ThreadLocalStorageLifecycle();
 }