We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import net.hasor.core.AppContext; import net.hasor.core.Hasor; import net.hasor.core.aop.SimplePropertyDelegate; import net.hasor.utils.BeanUtils; import org.junit.Test;
/**
public class PropertyDelegateTest { @test public void test(){ // 注册两个 Bean 并且共享同一个 name 属性。 AppContext appContext = Hasor.create().build(apiBinder -> { SimplePropertyDelegate delegate = new SimplePropertyDelegate("helloWord"); apiBinder.bindType(PojoBean1.class).dynamicProperty("name", String.class, delegate); apiBinder.bindType(PojoBean2.class).dynamicProperty("name", String.class, delegate); }); // 创建两个 Bean PojoBean1 pojoBean1 = appContext.getInstance(PojoBean1.class); PojoBean2 pojoBean2 = appContext.getInstance(PojoBean2.class); // assert BeanUtils.readProperty(pojoBean1, "name").equals("helloWord"); assert BeanUtils.readProperty(pojoBean2, "name").equals("helloWord"); BeanUtils.writeProperty(pojoBean1, "name", "newValue"); assert BeanUtils.readProperty(pojoBean1, "name").equals("newValue"); assert BeanUtils.readProperty(pojoBean2, "name").equals("newValue"); } }
class PojoBean1{ private String uuid;
public String getUuid() { return uuid; } public void setUuid(String uuid) { this.uuid = uuid; }
}
class PojoBean2{ private String uuid;
The text was updated successfully, but these errors were encountered:
No branches or pull requests
import net.hasor.core.AppContext;
import net.hasor.core.Hasor;
import net.hasor.core.aop.SimplePropertyDelegate;
import net.hasor.utils.BeanUtils;
import org.junit.Test;
/**
**/
public class PropertyDelegateTest {
@test
public void test(){
// 注册两个 Bean 并且共享同一个 name 属性。
AppContext appContext = Hasor.create().build(apiBinder -> {
SimplePropertyDelegate delegate = new SimplePropertyDelegate("helloWord");
apiBinder.bindType(PojoBean1.class).dynamicProperty("name", String.class, delegate);
apiBinder.bindType(PojoBean2.class).dynamicProperty("name", String.class, delegate);
});
// 创建两个 Bean
PojoBean1 pojoBean1 = appContext.getInstance(PojoBean1.class);
PojoBean2 pojoBean2 = appContext.getInstance(PojoBean2.class);
//
assert BeanUtils.readProperty(pojoBean1, "name").equals("helloWord");
assert BeanUtils.readProperty(pojoBean2, "name").equals("helloWord");
BeanUtils.writeProperty(pojoBean1, "name", "newValue");
assert BeanUtils.readProperty(pojoBean1, "name").equals("newValue");
assert BeanUtils.readProperty(pojoBean2, "name").equals("newValue");
}
}
class PojoBean1{
private String uuid;
}
class PojoBean2{
private String uuid;
}
The text was updated successfully, but these errors were encountered: