My favorites | Sign in
Project Logo
       
Code license: Apache License 2.0
Labels: osgi, java, scala, ioc, di

Welcome at the BindForge!

From version 0.5 on, the latest source code can be found at BitBucket.

Currently, a major redesign of the configuration API takes place. Please check the test specification BindForgeModuleSpec for the latest DSL syntax. The documentation will be updated soon. New builds are already available on a maven repository. Please check the BindForge Maven example for further information.

Additionally, BindForge now relies on the Peaberry activation mechanism for the OSGi Extender features.

Introduction

BindForge provides a Scala configuration DSL on top of the Guice dependency injection framework. Special support for the Peaberry project is provided. The DSL layer stays compatible with normal Guice modules and can be used together with "classic" Guice configuration elements at the same time.

Example configuration:

import org.bindforge.BindForgeModule
val module = new BindForgeModule {
  def config() {
    %[ServiceA] to %[ServiceAImpl]
  } 
}
InjectorFactory.createInjector(module)

The above code will create a Guice module with one binding. The configuration is the equivalent to the Java code bind(ServiceA.class).to(ServiceAImpl.class).

More examples:

%[ServiceA] toInstance new ServiceAImpl

%[ServiceA] ? Names.named("testid") to %[ServiceAImpl]  // classic version
%[ServiceA] ? "testid" to %[ServiceAImpl]               // shorthand version for Names

%[ServiceA] to %[ServiceAImpl] in Scopes.SINGLETON

// callback will be called on instance creation of ServiceBImpl
%[ServiceB] to %[ServiceBImpl] callback {b =>  // 'b' will be of type ServiceBImpl 
  b.serviceA = get(%[ServiceA])                // get(...) provides access to the Injector
}

// Instruct BindForge to inject a method
%[ServiceB] to %[ServiceBImpl] callback {b =>
  inject(b.serviceA_=)
}

OSGi Peaberry examples:

Basic setup:

import org.bindforge.{BindForgeModule, OSGiSupport}
val module = new BindForgeModule with OSGiSupport {
  def config() {
  } 
}
InjectorFactory.createInjector(module, Peaberry.osgiModule(context))

More examples:

%[PackageAdmin] importService()                      // simple import
%[PackageAdmin] importService("service.vendor=ACME") // import with LDAP filter

%[ServiceAImpl] exportService()                      // simple service registration
%[ServiceAImpl] exportService("key" -> "value")      // registration with properties








Hosted by Google Code