I created an api that allows for fluent, programmatic configuration of an application context that also borrows some ideas from guice. I wanted to create configuration programmatically, but I didn't want to use annotations or use magic strings for configuring objects.
The example shows the basic api. Proxies are used to record the configuration . The recorded information is then used to populate a generic application context. The context can be used as a parent to an xml context or annotation based context, or vice versa. It is a very thin wrapper around the Spring api's so it plays nice with existing functionality.Code:SpruiceModule module = new SpruiceModule() { public void wire(Binder binder) { BeanConfig<Car> carConfig = binder.autowire("car", Car.class); carConfig.startWith().start(); carConfig.stopWith().turnOff(); BeanConfig<Engine> engineConfig = binder.autowire("engine", Engine.class); engineConfig.set().setHorsepower(200); engineConfig.initWith().primeEngine(); engineConfig.destroyWith().destroyEngine(); } }; ContextBuilder builder = new ContextBuilder(); builder.register(module); ModuleContext context = builder.createContext(); Car car = context.get("car");
The project, called Spruice, is hosted at google code. Any feedback from the Spring community would be appreciated.
Regards,
Mike


Reply With Quote
