WEBVTT

1
00:00.860 --> 00:02.540
Hi everyone!

2
00:03.050 --> 00:06.800
We already know what is the.

3
00:06.950 --> 00:11.720
A tightly coupled and loosely coupled, right?

4
00:11.840 --> 00:16.700
And the idea of inversion control is in the inverse the control.

5
00:18.050 --> 00:18.410
Okay.

6
00:18.440 --> 00:21.680
We are already familiar with that right.

7
00:22.160 --> 00:26.330
And in this video let me refactor the existing cost.

8
00:29.660 --> 00:31.130
Into the.

9
00:34.610 --> 00:36.020
Inversion of control.

10
00:38.360 --> 00:41.150
So how I can do that.

11
00:41.210 --> 00:46.880
If you notice in the app.controller.ts, it use the syntax like this, right?

12
00:46.910 --> 00:56.420
It is something similar, but right now I will forcus on that

13
00:56.900 --> 00:59.180
I will comment this this thing.

14
00:59.990 --> 01:03.940
Okay, this is clear a tightly coupled

15
01:06.970 --> 01:11.890
And in order to reverse that, we will use the constructor okay.

16
01:12.520 --> 01:15.610
And with the constructor we will have a test service.

17
01:18.040 --> 01:22.420
Very similar with the the video.

18
01:24.460 --> 01:25.600
The previous video.

19
01:26.080 --> 01:27.670
And I will use this.

20
01:28.150 --> 01:33.880
And we must initialize the test service.

21
01:36.520 --> 01:37.330
Test service.

22
01:40.600 --> 01:43.600
And testService = testService

23
01:44.320 --> 01:44.800
That is.

24
01:48.040 --> 01:57.610
And actually we can use access modifier in right here, I will use the private and this will be work.

25
01:57.700 --> 02:01.720
But in app controller is used very shorthand syntax.

26
02:01.720 --> 02:02.140
Right.

27
02:02.680 --> 02:11.910
And actually we can use that, instead of initially right here and right here, we can use something like

28
02:11.910 --> 02:12.360
this.

29
02:13.170 --> 02:14.640
Let let me show you.

30
02:15.060 --> 02:18.180
I will comment, I will duplicate and comment.

31
02:20.760 --> 02:21.330
Right here.

32
02:21.840 --> 02:28.230
I can remove here remove here and provide a private.

33
02:30.840 --> 02:31.290
Okay.

34
02:31.320 --> 02:31.980
That's it

35
02:36.090 --> 02:39.330
This a similar with here.

36
02:39.450 --> 02:40.020
Okay.

37
02:40.050 --> 02:41.790
But this is a shorthand method.

38
02:42.120 --> 02:50.070
We can use the private into directly inside the constructor parameter.

39
02:50.070 --> 02:51.330
And this will work.

40
02:51.450 --> 02:55.680
And we can use the read only to make sure we don't change.

41
02:55.920 --> 02:58.410
We we don't change the test service.

42
02:59.670 --> 03:00.060
Okay.

43
03:00.090 --> 03:00.750
Read only.

44
03:02.430 --> 03:07.930
And if I remove everything right here Now, can you guess it worked or not?

45
03:09.430 --> 03:16.120
Well, if I go to the calc here because the calc get method right here is use the test service

46
03:16.150 --> 03:16.780
Right.

47
03:17.170 --> 03:22.240
If I go to here and if I refresh.

48
03:24.910 --> 03:27.310
Now it's not working.

49
03:28.420 --> 03:28.990
Right.

50
03:29.710 --> 03:30.160
The.

51
03:32.710 --> 03:35.200
It's crashed my application.

52
03:35.200 --> 03:35.950
Right.

53
03:37.090 --> 03:47.200
And in order to understand this issue, we will discuss on the dependency injection.

54
03:48.790 --> 03:49.270
Okay.

55
03:49.300 --> 03:50.560
Dependency injection.

56
03:51.040 --> 03:56.710
And because we already know what is the tightly coupled and loosely coupled

57
03:56.710 --> 04:00.100
And we already understand the inversion of control.

58
04:00.130 --> 04:02.980
Now let's understand the dependency injection.

59
04:02.980 --> 04:05.350
I will see you in the next video.