当前位置: 首页>>代码示例>>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;未经允许,请勿转载。