alexey-petrusevich / alexey-petrusevich/IMDB

Create ServiceContainer

Abierto
#3 0 comentarios 0 reacciones 0 asignados Ver en GitHub
enhancement good first issue
Lenguaje dominante
Java
Estrellas
0
Forks
0
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

You should create the ServiceContainer. ServiceContainer - it will be special helper class (singleton) which will provide possibility to create special objects (let's name them "Services") and get access to them which can be used in several classes.

Main plus in this class will be that you could create Services using annotations (```@Service``` - for example).

```
interface SystemService {
void init(Map initParams);
}
```

```
@Service
public class DatabaseService implements SystemService {
...
}
```

At start of your application you should read all project's directories and read all classes that have ```@Service``` annotation. After that you will have Class instances, check - if it implements SystemService interface or not, if not - throw exception (custom, something like - IllegalServiceImplementation). If everything is good - create instance of Service and pass parameter's map.

Main question is - what is this Services using for? Let's look at the example: You have a database and you have a lot of places where you need to use connection to DB, but it will be strange to create this connection every time, better solution will be to create one object (singleton) and store a lot of connections to DB (that you created before) and return it on every request to this singleton.

Dev hints:
About annotations:
( https://www.baeldung.com/java-custom-annotation , https://habr.com/ru/post/139736/ )

To read project dirs, check that is class implements something and create instances of classes you must use Reflection
( https://www.geeksforgeeks.org/reflection-in-java/ , https://stackoverflow.com/questions/37628/what-is-reflection-and-why-is-it-useful )

About singletons:
( https://habr.com/ru/post/129494/ )

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.