alexey-petrusevich / alexey-petrusevich/IMDB

Create ServiceContainer

Đang mở
#3 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement good first issue
Ngôn ngữ chính
Java
Star
0
Fork
0
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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/ )

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.