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(); }; }
protected virtual IDictionary findHttpDictionary() { if (!HttpContextLifecycle.HasContext()) { throw new StructureMapException(309); } return(HttpContext.Current.Items); }
public void Should_throw_when_context_is_not_available() { // Arrange var lifecycle = new HttpContextLifecycle(); HttpContextLifecycle.HasContextResolver = () => false; // Act & assert Assert.Throws <InvalidOperationException>(() => lifecycle.FindCache()); }
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(); }; }
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); }
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(); }; }
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.")); }
/// <summary> /// /// </summary> public static void ApplicationEndRequest() { try { foreach (var task in ContainerManager.Container.GetAllInstances <IRunAfterEachRequest>()) { task.Execute(); } } catch (Exception) { HttpContextLifecycle.DisposeAndClearAll(); } }
protected void Application_EndRequest(object sender, EventArgs e) { try { foreach (var task in ProjectObjectFactory.Container.GetAllInstances <IRunAfterEachRequest>()) { task.Execute(); } } catch (Exception) { HttpContextLifecycle.DisposeAndClearAll(); } }
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 } }; }
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); } }
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)); }
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(); } }; }
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(); }
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)); }
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()"); }; }
public IObjectCache FindCache() { return(HttpContextLifecycle.HasContext() ? _http.FindCache() : _nonHttp.FindCache()); }
public void cleanup() { // SAMPLE: clean-up-http-context HttpContextLifecycle.DisposeAndClearAll(); // ENDSAMPLE }
public void OnResultExecuted(ResultExecutedContext filterContext) { HttpContextLifecycle.DisposeAndClearAll(); }
public void HandleIncomingRequestProcessed() { HttpContextLifecycle.DisposeAndClearAll(); }
private static void ShutDown() { NHibernateContext.EndTransactions(); HttpContextLifecycle.DisposeAndClearAll(); StructuremapConfig.StructureMapResolver.DisposeNestedContainer(); }
/// <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(); }
public static void HttpContextDisposeAndClearAll() { HttpContextLifecycle.DisposeAndClearAll(); }
protected void Application_EndRequest(object sender, EventArgs e) { HttpContextLifecycle.DisposeAndClearAll(); }