public override object Resolve(CreationContext context, IReleasePolicy releasePolicy)
        {
            var current = HttpContext.Current;

            if (current == null)
            {
                throw new InvalidOperationException(
                          "HttpContext.Current is null. PerWebRequestLifestyle can only be used in ASP.Net");
            }

            var cachedBurden = (Burden)current.Items[perRequestObjectId];

            if (cachedBurden != null)
            {
                return(cachedBurden.Instance);
            }
            PerWebRequestLifestyleModule.EnsureInitialized();

            var burden = base.CreateInstance(context, true);

            current.Items[perRequestObjectId] = burden;
            PerWebRequestLifestyleModule.RegisterForEviction(this, burden);
            Track(burden, releasePolicy);
            return(burden.Instance);
        }
        public void Dispose()
        {
            var scope = PerWebRequestLifestyleModule.YieldScope();

            if (scope != null)
            {
                scope.Dispose();
            }
        }
Beispiel #3
0
		public void TestFixtureSetup()
		{
			//Hackery in order to get the PerWebRequest lifecycle working in a test environment
			//Surely there must be a better way to do this?
			HttpContext.Current = new HttpContext(new HttpRequest("foo", "http://localhost", ""), new HttpResponse(new StringWriter()));
			HttpContext.Current.ApplicationInstance = new HttpApplication();
			var module = new PerWebRequestLifestyleModule();
			module.Init(HttpContext.Current.ApplicationInstance);

			container = ContainerBuilder.Build("Windsor.config");
		}
		public void SetUp()
		{
			container = new WindsorContainer()
				.Register(Component.For<INHibernateInstaller>().ImplementedBy<ExampleInstaller>())
				.AddFacility<AutoTxFacility>()
				.AddFacility<NHibernateFacility>(
					fac => fac.DefaultLifeStyle = DefaultSessionLifeStyleOption.SessionPerWebRequest);
			var app = new HttpApplication();
			var lifestyle = new PerWebRequestLifestyleModule();
			lifestyle.Init(app);
		}
        public void tt()
        {
            var tw = new StringWriter();
            var wr = new SimpleWorkerRequest("/", Directory.GetCurrentDirectory(), "default.aspx", null, tw);
            var module = new PerWebRequestLifestyleModule();

            var ctx = HttpModuleRunner.GetContext(wr, new[] {module});
            HttpContext.Current = ctx.Key;

            var container = new WindsorContainer(new MockProxyFactory());
            container.Kernel.ComponentDestroyed += Kernel_ComponentDestroyed;
            container.AddComponentLifeStyle<SomeComponent>(LifestyleType.PerWebRequest);
            var c1 = container.Resolve<SomeComponent>();
            HttpModuleRunner.ProcessRequest(ctx.Value, ctx.Key);
            container.Release(c1);
            var c2 = container.Resolve<SomeComponent>();
            Assert.AreNotSame(c1, c2);
        }
 public ILifetimeScope GetScope(CreationContext context)
 {
     return(PerWebRequestLifestyleModule.GetScope());
 }