Builds a proxy type using composition.
In order for this builder to work, the target must implement one or more interfaces.
Inheritance: Spring.Proxy.AbstractProxyTypeBuilder
Ejemplo n.º 1
0
        public void ClearWithDynamicProxies()
        {
            CompositionProxyTypeBuilder typeBuilder = new CompositionProxyTypeBuilder();
            typeBuilder.TargetType = typeof(TestObject);
            Type proxyType = typeBuilder.BuildProxyType();

            DefaultListableObjectFactory of = new DefaultListableObjectFactory();
            RootObjectDefinition od1 = new RootObjectDefinition(proxyType, false);
            od1.PropertyValues.Add("Name", "Bruno");
            of.RegisterObjectDefinition("testObject", od1);

            GenericApplicationContext ctx1 = new GenericApplicationContext(of);
            ContextRegistry.RegisterContext(ctx1);

            ITestObject to1 = ContextRegistry.GetContext().GetObject("testObject") as ITestObject;
            Assert.IsNotNull(to1);
            Assert.AreEqual("Bruno", to1.Name);

            DefaultListableObjectFactory of2 = new DefaultListableObjectFactory();
            RootObjectDefinition od2 = new RootObjectDefinition(proxyType, false);
            od2.PropertyValues.Add("Name", "Baia");
            of2.RegisterObjectDefinition("testObject", od2);
            GenericApplicationContext ctx2 = new GenericApplicationContext(of2);

            ContextRegistry.Clear();

            ITestObject to2 = ctx2.GetObject("testObject") as ITestObject;
            Assert.IsNotNull(to2);
            Assert.AreEqual("Baia", to2.Name);
        }
        protected override IProxyTypeBuilder GetProxyBuilder()
        {
            CompositionProxyTypeBuilder pb = new CompositionProxyTypeBuilder();

            pb.ExplicitInterfaceImplementation = true;
            return(pb);
        }
		protected override IProxyTypeBuilder GetProxyBuilder()
		{
			CompositionProxyTypeBuilder pb = new CompositionProxyTypeBuilder();
            pb.ExplicitInterfaceImplementation = true;
            return pb;
		}
Ejemplo n.º 4
0
 public void CanBuildProxyForClassWithProtectedConstructor()
 {
     CompositionProxyTypeBuilder typeBuilder = new CompositionProxyTypeBuilder();
     typeBuilder.TargetType = typeof(ClassWithProtectedCtor);
     typeBuilder.BuildProxyType();            
 }