Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

AEM Service Interfaces

Avatar

Avatar
Validate 1
Level 1
rohand104
Level 1

Likes

3 likes

Total Posts

3 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
Applaud 5
View profile

Avatar
Validate 1
Level 1
rohand104
Level 1

Likes

3 likes

Total Posts

3 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
Applaud 5
View profile
rohand104
Level 1

11-09-2019

Why do we need an interface for every service in AEM?

Can we use @reference or @inject services without an interface?

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Give Back 5
MVP
Umesh_Sondhi
MVP

Likes

56 likes

Total Posts

64 posts

Correct Reply

28 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back
Boost 50
Boost 5
View profile

Avatar
Give Back 5
MVP
Umesh_Sondhi
MVP

Likes

56 likes

Total Posts

64 posts

Correct Reply

28 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back
Boost 50
Boost 5
View profile
Umesh_Sondhi
MVP

11-09-2019

Hi

Using interfaces is a good practice to decouple the user of a service from the implementation. In many cases you even want to have an API bundle so the user of the service does not need a maven dependency to the implementing bundle.On the other hand, you are not required to use interfaces. Especially when u wire components inside a bundle interfaces,it is often an unnecessary layer. In this case simply export the service directly with the class.

@Component(service = AbcService.class)

public class AbcService {
...
}

for client code

@Reference
private AbcService abcService;

So the difference is that you have to specify the service property if you want to export a component with its implementation class.

Answers (0)