Hi!
I'd like to throw in another pair of useful Apache DeltaSpike features which are heavily related to configuration.
First of all, for me the main focus of 'configuration' is to have exactly one and the same binary and be able to set it into production on various different servers and environments WITHOUT having to re-package it.
If the ReleaseManager creates a WAR file then this exact WAR must get installed on the test system, later moved to the staging environment and then on the boxes of various customers. And no one must ever open the WAR and tweak something inside of it. Otherwise most of the testing effort is nuts...
So here comes the ProjectStage. Taken from Rails to JSF, and further enhanced in Apache MyFaces CODI (originally) and later copied over to Apache DeltaSpike as well.
Now what has this to do with CDI and @Exclude?
The point is that we use the ProjectStage AND/OR values configured via ConfigSource for switching between implementations using @Exclude.
A small example.
Consider an interface MailService with public void sendMail(String from, String to, String subject, String body);
And we also have a default implementation which uses SMTP on a real server (the server IP could btw be configured via @ConfigParam...)
@ApplicationScoped
public class MailServiceImpl implements MailService {...}
But for our unit tests and local development we do not like to stress our production server. Thus we simply write an alternative impl which only logs the mail to send:
@ApplicationScoped
@Alternative
@Exclude(exceptIfProjectStage={ProjectStage.UnitTest.class, ProjectStage.Development.class})
public class MockMailService implements MailService {..}
Of course we also could have a 3rd MailService which does SSL in a very similar way.
Another example:
We use the property 'dbvendor' to tell our app which database vendor it should use.
We have a SomeDomainSearchService which does plain JPA.
But we also have a 'tuned' version for Oracle which uses NativeQueries:
@ApplicationScoped
@Specializes
@Exclude(onExpression="dbvendor!=oracle")
OracleSomeDomainSearchService extends SomeDomainSearchService {..
I hope you get the idea and the power it unlocks...
LieGrue,
strub