Ejemplo n.º 1
0
        public void ZyanComponentWithSharedPolicyAttribute_IsRegisteredAsSingleton()
        {
            using (var cat = new ComponentCatalog())
            {
                cat.RegisterComponents(MefCatalog);

                // get component registration
                var reg = cat.GetRegistration("UniqueName_MefSample13");
                Assert.IsNotNull(reg);
                Assert.AreEqual(ActivationType.Singleton, reg.ActivationType);

                // get component instance
                var obj = cat.GetComponent("UniqueName_MefSample13") as IMefSample;
                Assert.IsNotNull(obj);
                AssertEx.IsInstanceOf <MefSample13>(obj);
                var ms13 = (MefSample13)obj;
                var guid = ms13.Guid;

                // make sure component instance is not cleaned up
                cat.CleanUpComponentInstance(reg, obj);
                Assert.AreEqual(guid, ms13.Guid);

                // make sure component instance is not disposed with component catalog
                cat.Dispose();
                Assert.AreEqual(guid, ms13.Guid);
            }
        }
Ejemplo n.º 2
0
        public void SharedZyanComponentFromMefContainer_IsRegistered()
        {
            using (var cat = new ComponentCatalog())
            {
                cat.RegisterComponents(MefContainer);

                // get component registration
                var reg = cat.GetRegistration("UniqueName_MefSample9");
                Assert.IsNotNull(reg);
                Assert.AreEqual(ActivationType.Singleton, reg.ActivationType);

                // get component instance
                var obj = cat.GetComponent("UniqueName_MefSample9") as IMefSample;
                Assert.IsNotNull(obj);
                AssertEx.IsInstanceOf <MefSample9>(obj);
                Assert.AreNotEqual(0, MefSample9.InstanceCount);

                // make sure component instance is not cleaned up
                cat.CleanUpComponentInstance(reg, obj);
                Assert.AreNotEqual(0, MefSample9.InstanceCount);

                // make sure component instance is not disposed with catalog
                cat.Dispose();
                Assert.AreNotEqual(0, MefSample9.InstanceCount);
            }
        }