Now, it's time to replace her application, deep context with the category repository when we're using
application deep context.
We were getting that because we've registered that inside our services right here now.
This time we want the implementation of the AI category repository, but we have not registered that
in our container.
So to register, we will have to do better dart services dart and we have to specify the lifetime that
three lifetime that we have a singleton scoped and transient singleton basically means that there will
be one object of that and that will be used throughout the lifecycle unless you restart the application
scope.
That means that when you hit the button and the request is received, that will be the scope of that
object.
Then you hit the button next time or on the next request, a new object instance where we created.
Transient, is this polished off our lifetime?
Transient means every time it will create a new object.
So let's say you hit a button and on that button, click if you request your database three times,
transient will create three instance of the deep context.
So transient is something you should be very careful about because in a request, if an object is requested
100 times, then it will create 100 different instances of the object.
When we are working with database scope is what you should be using.
So we will be adding here the lifetime, which is X Corp and we register something to our container.
We want to register the AI category repository.
We really do control to act the closing statement.
This is the interface.
Then we have to define which Glass will implement this interface.
So that is the category that secretary.
What this will do is whenever we request an object of a category repository, it will give us the implementation
that we have defined inside the category repository.
It is pretty smart when it comes to dependency injection.
So once we have defined that in our container, we can go back to our controller here and rather than
application DB context.
Now we want a category that that we.
I can just call that the same underscored DP, that's OK.
But here we will be getting an implementation of category that positively in our DP.
Now let's modify old action methods.
First is the index.
Here, we want to get all the categories.
We have a method which is get on that word, retrieve all the categories.
Next, what we have is create.
We want to add that to the database of countries for DP.
We have to add method, and that's perfect.
Once we had, we will have to explicitly call it the safe method inside the category depository to save
the changes.
If you don't call this, then the object will not get added to the database.
Let's go to what added, we have the first our default, the method name that we have inside our repository
is get first our default and we have programmed it that it is able to process the expression just like
we had inside the first hour default.
So that is great.
Next, we have the edited category post action method here, we just call, update and see if changes.
Lastly, we have the delayed we can uncomment this use the first default, which will be at first our
default and perfect on the post, we need to call the first our default again so I can just copy this.
They stood here to find the category based on the I.D. and then on underscore TB, we have to remove
and save changes.
So with this, we have replaced the application debate context with suppository for category.
Let's run the application and make sure everything works.
If you did not add the category repository to the container, you will get an error right here with
that.
Let's go to a category.
It perfect it is able to retrieve all the categories.
Let's try to create a test category if you hit edit here we get an error page not found.
That's not likely possible.
Let's go back to what category controller and examine and get action matter.
And of course, we were playing around here, so we changed that to video.
And that's why it was not working.
I need to make sure that this is the same in other places as well.
That is it.
And perfect.
Let's try that one more time.
Let's go to our category.
Try to edit this.
Backward.
Let's delete.
And perfect, all the credit operations are working as expected, but this time we are using the categories
at that we.