當前位置: 首頁>>代碼示例>>C#>>正文


C# DefaultListableObjectFactory.PreInstantiateSingletons方法代碼示例

本文整理匯總了C#中Spring.Objects.Factory.Support.DefaultListableObjectFactory.PreInstantiateSingletons方法的典型用法代碼示例。如果您正苦於以下問題:C# DefaultListableObjectFactory.PreInstantiateSingletons方法的具體用法?C# DefaultListableObjectFactory.PreInstantiateSingletons怎麽用?C# DefaultListableObjectFactory.PreInstantiateSingletons使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Spring.Objects.Factory.Support.DefaultListableObjectFactory的用法示例。


在下文中一共展示了DefaultListableObjectFactory.PreInstantiateSingletons方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ExtensiveCircularReference

 public void ExtensiveCircularReference()
 {
     DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
     for (int i = 0; i < 1000; i++)
     {
         MutablePropertyValues pvs = new MutablePropertyValues();
         pvs.Add(new PropertyValue("Spouse", new RuntimeObjectReference("object" + (i < 99 ? i + 1 : 0))));
         RootObjectDefinition rod = new RootObjectDefinition(typeof(TestObject), pvs);
         lof.RegisterObjectDefinition("object" + i, rod);
     }
     lof.PreInstantiateSingletons();
     for (int i = 0; i < 1000; i++)
     {
         TestObject obj = (TestObject)lof.GetObject("object" + i);
         TestObject otherObj = (TestObject)lof.GetObject("object" + (i < 99 ? i + 1 : 0));
         Assert.IsTrue(obj.Spouse == otherObj);
     }
 }
開發者ID:ouyangyl,項目名稱:MySpringNet,代碼行數:18,代碼來源:DefaultListableObjectFactoryTests.cs

示例2: SingletonFactoryObjectMustNotCreatePrototypeOnPreInstantiateSingletonsCall

        public void SingletonFactoryObjectMustNotCreatePrototypeOnPreInstantiateSingletonsCall()
        {
            DefaultListableObjectFactory lof = new DefaultListableObjectFactory();

            RootObjectDefinition def = new RootObjectDefinition();
            def.ObjectType = typeof(DummyFactory);
            def.IsSingleton = true;
            def.PropertyValues.Add("IsSingleton", false);

            DummyFactory.Reset();

            Assert.IsFalse(DummyFactory.WasPrototypeCreated,
                           "Prototype appears to be instantiated before the test is even run.");
            lof.RegisterObjectDefinition("x1", def);
            Assert.IsFalse(DummyFactory.WasPrototypeCreated,
                           "Prototype instantiated after object definition registration (must NOT be).");
            lof.PreInstantiateSingletons();
            Assert.IsFalse(DummyFactory.WasPrototypeCreated,
                           "Prototype instantiated after call to PreInstantiateSingletons(); must NOT be.");
            lof.GetObject("x1");
            Assert.IsTrue(DummyFactory.WasPrototypeCreated, "Prototype was not instantiated.");
        }
開發者ID:ouyangyl,項目名稱:MySpringNet,代碼行數:22,代碼來源:DefaultListableObjectFactoryTests.cs

示例3: PreInstantiateSingletonsMustNotIgnoreObjectsWithUnresolvedObjectTypes

 public void PreInstantiateSingletonsMustNotIgnoreObjectsWithUnresolvedObjectTypes()
 {
     KnowsIfInstantiated.ClearInstantiationRecord();
     DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
     Assert.IsTrue(!KnowsIfInstantiated.WasInstantiated, "Singleton appears to be instantiated before the test is even run.");
     RootObjectDefinition def = new RootObjectDefinition();
     def.ObjectTypeName = typeof(KnowsIfInstantiated).FullName;
     lof.RegisterObjectDefinition("x1", def);
     Assert.IsTrue(!KnowsIfInstantiated.WasInstantiated, "Singleton appears to be instantiated before PreInstantiateSingletons() is invoked.");
     lof.PreInstantiateSingletons();
     Assert.IsTrue(KnowsIfInstantiated.WasInstantiated, "Singleton was not instantiated by the container (it must be).");
 }
開發者ID:ouyangyl,項目名稱:MySpringNet,代碼行數:12,代碼來源:DefaultListableObjectFactoryTests.cs

示例4: LazyInitialization

        public void LazyInitialization()
        {
            KnowsIfInstantiated.ClearInstantiationRecord();
            DefaultListableObjectFactory lof = new DefaultListableObjectFactory();

            RootObjectDefinition def = new RootObjectDefinition();
            def.ObjectTypeName = typeof(KnowsIfInstantiated).FullName;
            def.IsLazyInit = true;
            lof.RegisterObjectDefinition("x1", def);

            Assert.IsTrue(!KnowsIfInstantiated.WasInstantiated, "Singleton appears to be instantiated before the test is even run.");
            lof.RegisterObjectDefinition("x1", def);
            Assert.IsTrue(!KnowsIfInstantiated.WasInstantiated, "Singleton appears to be instantiated before PreInstantiateSingletons() is invoked.");
            lof.PreInstantiateSingletons();
            Assert.IsFalse(KnowsIfInstantiated.WasInstantiated, "Singleton was instantiated by the container (it must NOT be 'cos LazyInit was set to TRUE).");
            lof.GetObject("x1");
            Assert.IsTrue(KnowsIfInstantiated.WasInstantiated, "Singleton was not instantiated by the container (it must be).");
        }
開發者ID:ouyangyl,項目名稱:MySpringNet,代碼行數:18,代碼來源:DefaultListableObjectFactoryTests.cs

示例5: DisposeCyclesThroughAllSingletonsEvenIfTheirDisposeThrowsAnException

        public void DisposeCyclesThroughAllSingletonsEvenIfTheirDisposeThrowsAnException()
        {
            RootObjectDefinition foo = new RootObjectDefinition(typeof(GoodDisposable));
            foo.IsSingleton = true;
            RootObjectDefinition bar = new RootObjectDefinition(typeof(BadDisposable));
            bar.IsSingleton = true;
            RootObjectDefinition baz = new RootObjectDefinition(typeof(GoodDisposable));
            baz.IsSingleton = true;

            using (DefaultListableObjectFactory fac = new DefaultListableObjectFactory())
            {
                fac.RegisterObjectDefinition("foo", foo);
                fac.RegisterObjectDefinition("bar", bar);
                fac.RegisterObjectDefinition("baz", baz);
                fac.PreInstantiateSingletons();
            }
            Assert.AreEqual(2, GoodDisposable.DisposeCount, "All IDisposable singletons must have their Dispose() method called... one of them bailed, and as a result the rest were (apparently) not Dispose()d.");
            GoodDisposable.DisposeCount = 0;
        }
開發者ID:ouyangyl,項目名稱:MySpringNet,代碼行數:19,代碼來源:DefaultListableObjectFactoryTests.cs


注:本文中的Spring.Objects.Factory.Support.DefaultListableObjectFactory.PreInstantiateSingletons方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。