Java??????IOC???Guice
???????????? ???????[ 2015/3/3 14:39:10 ] ????????Java ??????? ???
????Module???????
????Guice????????????????????AbstractModule?????configure????????configure???????????????Binder??????????
????Binder????????γ????????????DSL???磺
?????????????binder.bind(serviceClass).to(implClass).in(Scopes.[SINGLETON | NO_SCOPE]);
??????base??????????binder.bind(implClass).in(Scopes.[SINGLETON | NO_SCOPE]);
????service????????binder.bind(serviceClass).toInstance(servieInstance).in(Scopes.[SINGLETON | NO_SCOPE]);
?????????????????binder.bind(serviceClass).annotatedWith(Names.named(“name”)).to(implClass).in(Scopes.[SINGLETON | NO_SCOPE]);
????????????????@Provides??????????????spring??@Bean??
????@ImplementedBy??????????????????@ImplementedBy?????????????????е?OO????????????????????
????????????????????????????????@Inject???????????????????????????????@Named??????磺
public void configure() {
final Binder binder = binder();
//TODO: bind named instance;
binder.bind(NamedService.class).annotatedWith(Names.named("impl1")).to(NamedServiceImpl1.class);
binder.bind(NamedService.class).annotatedWith(Names.named("impl2")).to(NamedServiceImpl2.class);
}
@Inject
public List<NamedService> getAllItemServices(@Named("impl1") NamedService nameService1??
@Named("impl2") NamedService nameService2) {
}
Guice?????????@Provides????????????????????
@Provides
public List<NamedService> getAllItemServices(@Named("impl1") NamedService nameService1??
@Named("impl2") NamedService nameService2) {
final ArrayList<NamedService> list = new ArrayList<NamedService>();
list.add(nameService1);
list.add(nameService2);
return list;
}
????Guice???
?????????????Guice module???????????????????????????÷???????????μ?github .
package com.github.greengerong.app;
/**
* ***************************************
* *
* Auth: green gerong *
* Date: 2014 *
* blog: http://greengerong.github.io/ *
* github: https://github.com/greengerong *
* *
* ****************************************
*/
public class AppModule extends AbstractModule {
private static final Logger LOGGER = LoggerFactory.getLogger(AppModule.class);
private final BundleContext bundleContext;
public AppModule(BundleContext bundleContext) {
this.bundleContext = bundleContext;
LOGGER.info(String.format("enter app module with: %s"?? bundleContext));
}
@Override
public void configure() {
final Binder binder = binder();
//TODO: bind interface
binder.bind(ItemService.class).to(ItemServiceImpl.class).in(SINGLETON);
binder.bind(OrderService.class).to(OrderServiceImpl.class).in(SINGLETON);
//TODO: bind self class(without interface or base class)
binder.bind(PriceService.class).in(Scopes.SINGLETON);
//TODO: bind instance not class.
binder.bind(RuntimeService.class).toInstance(new RuntimeService());
//TODO: bind named instance;
binder.bind(NamedService.class).annotatedWith(Names.named("impl1")).to(NamedServiceImpl1.class);
binder.bind(NamedService.class).annotatedWith(Names.named("impl2")).to(NamedServiceImpl2.class);
}
@Provides
public List<NamedService> getAllItemServices(@Named("impl1") NamedService nameService1??
@Named("impl2") NamedService nameService2) {
final ArrayList<NamedService> list = new ArrayList<NamedService>();
list.add(nameService1);
list.add(nameService2);
return list;
}
}
????Guice?????
????????Guice????????????????????Guice module?????Guice??????injector???磺
????Injector injector = Guice.createInjector(new AppModule(bundleContext));
????????????????module?????????????module??????????????
????Guice api??????
????public static Injector createInjector(Module... modules)
????public static Injector createInjector(Iterable<? extends Module> modules)
????public static Injector createInjector(Stage stage?? Module... modules)
????public static Injector createInjector(Stage stage?? Iterable<? extends Module> modules)
????Guice????????Region??????????State?????state??? TOOL??DEVELOPMENT??PRODUCTION???;????DEVELOPMENT??????
????????
????????Guice?????demo??????μ?github .
????Guice???к????????AOP??????????????????set??map??OSGI??UOW?????????μ?Guice wiki.
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Java???????????Щ???????????????Java????????????????Java?б???Map????????Java Web???????????????Java??????????????д?????Java????????7???????????????????????(java .net ?????)???Java??????????Python??????Java webdriver??λ????????′????е?????Java??д??????????????????Java???????????????JavaScript????????????Java?????????????????? Java???????10??????????????Java?м????????????????java???????ü???????????м???????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????