Sunday, 20 September 2009

And after the holidays...

I resumed my day job this last week and it wasn't very bad :) at all . So this weekend I resumed my work on jEmbedded. First of all, thanks to all the people who took the time to try it and sent me their comments, you have helped me a lot. Even though it was a early release it has given me a lot of insight in which direction I should go.

I decided to release the version 0.1.1 in the next few days that will be focused in:
  • Improved Spring Integration: The @Inject annotation will be able to reference a Spring Bean and more.
  • Improved Documentation.
  • Improved Web Support.
  • More examples: I'm adding several examples that I'm working on as a complete example of a Invoicing System including Spring MVC integration and a hierarchical services layer (you can have an early peek on the project website). That will show a lot of the jEmbedded features as creating and composing a service layer in a few minutes. Other examples will include jIntegrationTest-0.1, how to package services with jEmbedded etc...
  • Bug fixes and code refactoring.

Tuesday, 1 September 2009

jEmbedded - FAQ III

Well I'm going abroad for my holidays (it's time at last !!) so I won't be writing in a while.

I've just created a new discussion group jEmbedded Discussion Group so you are free to join and post your questions, requests etc...

After holidays want I'm going to do it's to write down a full documentation and upload more examples.

In the meantime here it's more Q/A:

* What's the difference between the @Include and @Repository annotations?

With these two annotations resources can be added to the container but in a different manner as @Repository will create a new container for the resources and @Include will just add them to the current container (default container in case you haven't provided the @Repository ann).

Use @Include if you only want to add some extra resources to the container and not to create a new one.

* Spring Integration, how to do it?

There are many different ways to do this. I've provided a spring-support-module that will help you, but in this stage it's not very comprehensive as I've focused to provide a stand alone IoC container.

In this module a FactoryBean class is provided so an instance of the embedded container can be stored into the spring-context. Then you can inject the container in any bean you want, get the container from Spring or just use ContainerHolder.getCurrentThreadContainer().
Please have a look at the spring-integration-module and the embedded-database example for more information.

You may ignore the integration module and write your own FactoryBean:

@Container(instanceType=
ContainerInstanceType.xxxx)
@Repository(id="database-service-layer", resources={EmbeddedDatabaseImpl.class})
public class EmbeddedDatabaseFactory implements FactoryBean {

public Object getObject() throws Exception {
return EmbeddedHandlerFactory.getInstance(getClass());
}

public Class getObjectType() {
return EmbeddedHandler.class;
}

public boolean isSingleton() {
return false;
}

}

Then you can retrieve the container like this:

ApplicationContex appContex; //SpringContext

EmbeddedHandler handler = (EmbeddedHandler)appContext.getBean("factory-bean-id");

Finally, you can create the container in any spring bean you'd like. Of course watch out what kind of bean it is (singleton, prototype etc...)

* Can the annotation @Inject be used to reference a Spring bean?

No at this moment, but you can inject the container to any spring bean or just accessing the container with ContainerHolder. I will add this feature in the near future.