Alec
Alec

Reputation: 1496

MEF (.NET) analogue for Java

I got very used to this clean syntax with MEF in .NET

[Export(typeof(ISomething))]
public class Something : ISomething {
}

Is there any analogy with annotations in Java? (& corresponding framework). Any dependency injection containers to be good compatible with?

Upvotes: 4

Views: 1174

Answers (2)

Alec
Alec

Reputation: 1496

From what I could find to the moment, I can use Google Guice with its annotations. There (in G.G.) they specify default implementer of interface rather then doing export of implementation (as in MEF). E.g.

@ImplementedBy(Something.class) 
public interface ISomething {
    ...
}

public class Something implements ISomething {
    ...
}

Constructor parameters injections etc are also somewhat possible from documentation.

Upvotes: 2

maba
maba

Reputation: 48075

There are several IoC containers available in Java. The two that comes to my mind are Spring with its IoC Container and Google Guice.

I have mostly worked with Spring IoC and find it very nice to work with.

Here is another good tutorial regarding Spring IoC.

Upvotes: 3

Related Questions