Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
Now that we've installed and configured our DI container, let's update our controller's action methods to call the appropriate entries repository methods.
Follow Along
To follow along committing your changes to this course, you'll need to fork the aspnet-fitness-frog-spa repo. Then you can clone, commit, and push your changes to your fork like this:
git clone <your-fork>
cd aspnet-fitness-frog-spa
git checkout tags/v3.2 -b calling-our-repository-methods
Now that we've installed and configured
our DI container, let's update our
0:00
controllers actions methods to call
the appropriate EntriesRepository methods.
0:04
In the first Get action method,
let's return a call,
0:11
To the entriesRepository.GetList method.
0:17
And in the second Get action method,
let's return a call to
0:24
the entriesRepository.Get method,
passing in the id parameter.
0:28
In the Post action method,
0:40
we need to call the entriesRepository
method to add the entry.
0:41
And in the Put action method,
0:51
we need to call the entriesRepository
method to update the entry.
0:54
And lastly, in the Delete action method,
1:07
we need to call the entriesRepository
method to delete the entry.
1:10
Set break points in the constructor
in the first Get action method, and
1:22
press F5 to start debugging.
1:27
Using Postman, let's make a Get request
1:39
against the api/entries endpoint.
1:44
Here we are in the constructor for
our API controller.
1:49
If we look in the Call Stack window,
we can see that the Call Stack includes
1:55
a call to the
SimpleInjectorWebApiInitializer.Initialize
2:00
method.
2:04
This is our controller being instantiated
2:05
as part of the DI container's
verification process.
2:08
Press F5 to continue execution.
2:11
And we're in the controller
constructor again.
2:14
This time,
2:17
our controller is being substantiated
to handle the current request.
2:18
If we hover over
the entriesRepository parameter,
2:21
we can see that we've been passed
a reference to an instance which in
2:25
turn has a reference to
a context class instance.
2:29
Looks like our DI container is up and
running.
2:33
Press F5 to continue execution.
2:37
And here we are in the Get action method,
2:40
about to make a call to
the entriesRepository.GetList method.
2:43
Go ahead and continue execution.
2:47
And we get an exception.
2:52
Right here is the exception message.
2:58
Self referencing loop detected with type
'Treehouse.FitnessFrog.Shared.Models.En-
3:01
try' Path '[0] .Activity.Entries'.
3:08
Looks like we've encountered an issue
with serializing our data to JSON.
3:11
Next up, let's take a closer look
at why this error's occurring, and
3:16
how we can configure
the JsonSerializer to prevent it.
3:19
You need to sign up for Treehouse in order to download course files.
Sign up