The TokenController

The next step will be to add a TokenController to issue and refresh tokens. Ideally speaking, it will be a good idea to inherit it from the BaseApiController base class we put together back in Chapter 5, Client-Server Interactions, so we can access our ApplicationDbContext. However, we will definitely need even more than that; since we'll be working with users, it would be nice to also have an (injected) instance of that UserManager class we did use when working on our DbSeeder class. On top of that, we'll definitely need to access the JWT configuration values we put in the AppSettings files a moment ago.

In order to have access to all these objects, we can choose between three possible approaches:

  1. Inject all this stuff in the TokenController constructor.
  2. Upgrade our existing BaseApiController class, empowering it with the DI object instances we need.
  3. Create another base controller class, similar to BaseApiController but with more stuff, and inherit the TokenController from it.

The former approach is viable enough, yet it has a minor issue--if we work on the TokenController only, we'll lose the chance to get the job done in advance for all the other controllers who will need that new stuff later on. For this very reason, the other two approaches seem to be more efficient; with that in mind, in order to keep our code base as thin as possible, we'll go with option #2.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.26.108