Exemplo n.º 1
0
		public void can_register_through_adapter_using_proxyfactory()
		{
			var catalog = new AssemblyCatalog(Assembly.GetAssembly(typeof(ClassWithBehaviour)));
			var proxycatalog = new ProxyCatalog(catalog);
			var container = new CompositionContainer(proxycatalog);

			var adapter = new MEFAdapter(container).WithProxyFactory<DynamicProxyFactory>();
            IoC.Initialize(adapter);

			adapter.Register(new[] { new PerRequest { Service = typeof(ClassWithBehaviour), Implementation = typeof(ClassWithBehaviour) } });

			var vm = container.GetExportedValue<ClassWithBehaviour>();
			Assert.That(vm, Is.InstanceOfType(typeof(INotifyPropertyChanged)));
		}
Exemplo n.º 2
0
		public void register_through_adapter_using_proxyfactory_can_resolve_perrequest()
		{
			var catalog = new AssemblyCatalog(Assembly.GetAssembly(typeof(ClassWithBehaviour)));
			var proxycatalog = new ProxyCatalog(catalog);
			var container = new CompositionContainer(proxycatalog);

			var adapter = new MEFAdapter(container).WithProxyFactory<DynamicProxyFactory>();
            IoC.Initialize(adapter);

			adapter.Register(new[] { new PerRequest { Service = typeof(ClassWithBehaviour), Implementation = typeof(ClassWithBehaviour) } });

			var sl = (IServiceLocator)adapter;
			var instance1 = sl.GetInstance<ClassWithBehaviour>();
			var instance2 = sl.GetInstance<ClassWithBehaviour>();

			Assert.AreNotSame(instance1, instance2);
		}