Hi everyone!
We already know what is the.
A tightly coupled and loosely coupled, right?
And the idea of inversion control is in the inverse the control.
Okay.
We are already familiar with that right.
And in this video let me refactor the existing cost.
Into the.
Inversion of control.
So how I can do that.
If you notice in the app.controller.ts, it use the syntax like this, right?
It is something similar, but right now I will forcus on that
I will comment this this thing.
Okay, this is clear a tightly coupled
And in order to reverse that, we will use the constructor okay.
And with the constructor we will have a test service.
Very similar with the the video.
The previous video.
And I will use this.
And we must initialize the test service.
Test service.
And testService = testService
That is.
And actually we can use access modifier in right here, I will use the private and this will be work.
But in app controller is used very shorthand syntax.
Right.
And actually we can use that, instead of initially right here and right here, we can use something like
this.
Let let me show you.
I will comment, I will duplicate and comment.
Right here.
I can remove here remove here and provide a private.
Okay.
That's it
This a similar with here.
Okay.
But this is a shorthand method.
We can use the private into directly inside the constructor parameter.
And this will work.
And we can use the read only to make sure we don't change.
We we don't change the test service.
Okay.
Read only.
And if I remove everything right here Now, can you guess it worked or not?
Well, if I go to the calc here because the calc get method right here is use the test service
Right.
If I go to here and if I refresh.
Now it's not working.
Right.
The.
It's crashed my application.
Right.
And in order to understand this issue, we will discuss on the dependency injection.
Okay.
Dependency injection.
And because we already know what is the tightly coupled and loosely coupled
And we already understand the inversion of control.
Now let's understand the dependency injection.
I will see you in the next video.