Web object definitions extend Spring.Objects.Factory.Support.RootObjectDefinition by adding scope property.

This is the most common type of object definition in ASP.Net web applications

Inheritance: Spring.Objects.Factory.Support.RootObjectDefinition, IWebObjectDefinition
Exemplo n.º 1
0
        public void CanBeUsedOnNonWebThread()
        {
            WebObjectFactory wof;
            RootWebObjectDefinition rwod;

            // we need to create WOF within a valid HttpContext environment 'cause we will 
            // make use of 'request' and 'session' scope.
            using (new VirtualEnvironmentMock("/somedir/some.file", null, null, "/", true))
            {
                wof = new WebObjectFactory("/somedir/", false);
            }

            rwod = new RootWebObjectDefinition(typeof(object), new ConstructorArgumentValues(), new MutablePropertyValues());
            rwod.Scope = ObjectScope.Application.ToString();
            wof.RegisterObjectDefinition("applicationScopedObject", rwod);

            rwod = new RootWebObjectDefinition(typeof(object), new ConstructorArgumentValues(), new MutablePropertyValues());
            rwod.Scope = ObjectScope.Request.ToString();
            wof.RegisterObjectDefinition("requestScopedObject", rwod);

            rwod = new RootWebObjectDefinition(typeof(object), new ConstructorArgumentValues(), new MutablePropertyValues());
            rwod.Scope = ObjectScope.Session.ToString();
            wof.RegisterObjectDefinition("sessionScopedObject", rwod);

            object o;
            o = wof.GetObject("applicationScopedObject");
            Assert.IsNotNull(o);

            AssertGetObjectThrows(typeof(ObjectCreationException), wof, "requestScopedObject");
            AssertGetObjectThrows(typeof(ObjectCreationException), wof, "sessionScopedObject");
        }
        public void CanBeUsedOnNonWebThread()
        {
            WebObjectFactory        wof;
            RootWebObjectDefinition rwod;

            // we need to create WOF within a valid HttpContext environment 'cause we will
            // make use of 'request' and 'session' scope.
            using (new VirtualEnvironmentMock("/somedir/some.file", null, null, "/", true))
            {
                wof = new WebObjectFactory("/somedir/", false);
            }

            rwod       = new RootWebObjectDefinition(typeof(object), new ConstructorArgumentValues(), new MutablePropertyValues());
            rwod.Scope = ObjectScope.Application.ToString();
            wof.RegisterObjectDefinition("applicationScopedObject", rwod);

            rwod       = new RootWebObjectDefinition(typeof(object), new ConstructorArgumentValues(), new MutablePropertyValues());
            rwod.Scope = ObjectScope.Request.ToString();
            wof.RegisterObjectDefinition("requestScopedObject", rwod);

            rwod       = new RootWebObjectDefinition(typeof(object), new ConstructorArgumentValues(), new MutablePropertyValues());
            rwod.Scope = ObjectScope.Session.ToString();
            wof.RegisterObjectDefinition("sessionScopedObject", rwod);

            object o;

            o = wof.GetObject("applicationScopedObject");
            Assert.IsNotNull(o);

            AssertGetObjectThrows(typeof(ObjectCreationException), wof, "requestScopedObject");
            AssertGetObjectThrows(typeof(ObjectCreationException), wof, "sessionScopedObject");
        }
 public void UnderstandsObjectScopePrototype()
 {
     RootWebObjectDefinition rwod = new RootWebObjectDefinition(typeof(object), new ConstructorArgumentValues(), new MutablePropertyValues());
     rwod.IsSingleton = false;
     Assert.IsFalse(rwod.IsPage);
     Assert.IsFalse(rwod.IsSingleton);
     Assert.IsTrue(rwod.IsPrototype);
     Assert.AreEqual(ObjectScope.Prototype, ((IWebObjectDefinition)rwod).Scope);
 }
        public void UnderstandsObjectScopePrototype()
        {
            RootWebObjectDefinition rwod = new RootWebObjectDefinition(typeof(object), new ConstructorArgumentValues(), new MutablePropertyValues());

            rwod.IsSingleton = false;
            Assert.IsFalse(rwod.IsPage);
            Assert.IsFalse(rwod.IsSingleton);
            Assert.IsTrue(rwod.IsPrototype);
            Assert.AreEqual(ObjectScope.Prototype, ((IWebObjectDefinition)rwod).Scope);
        }