Service Example #94
-
Hi, i noticed context.Services and i wonder how is the use case and example of services as it sounds powerful. Is there any example or guide i can follow? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It's for dependency injection. You shouldn't need to touch it in your routes, but the router uses it to resolve dependencies when running the routes (such as injecting loggers). You can see it in action in the Sample project.
All this, via the magic of dependency injection! |
Beta Was this translation helpful? Give feedback.
It's for dependency injection. You shouldn't need to touch it in your routes, but the router uses it to resolve dependencies when running the routes (such as injecting loggers). You can see it in action in the Sample project.
In
Startup.cs
I configure services to be injected, such as logging and HttpClient.In my resources, you can see that I inject a logger, even if I don't use it.
In the GitHub resource, I use the configured HttpClient to act as a pass-though to the GitHub api.
All this, via the magic of dependency injection!