public void GetRegistrationInfo_ContainerWithSingletonTypeRegistered() { var helper = new MefHelper(); var container = new CompositionContainer(); container.RegisterType(typeof(ITestInterface), typeof(TestClass1)); var registrationInfo = helper.GetRegistrationInfo(container, typeof(ITestInterface)); Assert.AreEqual(typeof(ITestInterface), registrationInfo.DeclaringType); Assert.AreEqual(RegistrationType.Singleton, registrationInfo.RegistrationType); }
public void ResolveType_Singleton() { var helper = new MefHelper(); var container = new CompositionContainer(); container.RegisterType <ITestInterface, TestClass1>(); var resolvedInstance1 = helper.ResolveType(container, typeof(ITestInterface)); Assert.IsNotNull(resolvedInstance1); Assert.IsInstanceOfType(resolvedInstance1, typeof(TestClass1)); var resolvedInstance2 = helper.ResolveType(container, typeof(ITestInterface)); Assert.IsNotNull(resolvedInstance2); Assert.IsInstanceOfType(resolvedInstance2, typeof(TestClass1)); Assert.IsTrue(ReferenceEquals(resolvedInstance1, resolvedInstance2)); }
public void ResolveType_Transient() { var helper = new MefHelper(); var container = new CompositionContainer(); container.RegisterType <ITestInterface, TestClass1>(); var resolvedInstance1 = helper.ResolveType(container, typeof(ITestInterface)); Assert.IsNotNull(resolvedInstance1); Assert.IsInstanceOfType(resolvedInstance1, typeof(TestClass1)); var resolvedInstance2 = helper.ResolveType(container, typeof(ITestInterface)); Assert.IsNotNull(resolvedInstance2); Assert.IsInstanceOfType(resolvedInstance2, typeof(TestClass1)); // Note that MEF does not support transient types Assert.IsTrue(ReferenceEquals(resolvedInstance1, resolvedInstance2)); }