You have already found the code responsible for executing the dependency injection. app.CreatePerOwinContext() is the code for registering usermanager (the delegate to create usermanager) in the Owin pipeline, which is actually just a dictionary, which is stored in the HttpContext .
You can read in detail how this mechanism works in this blogpost .
Regarding your other question, which I fully understand! Why check for null if a dependency is introduced ...? Good: this is because Owin is used here as a poor DI mechanism, and what you see in the default project template is actually a backup mechanism with the smell of an anti locator template . Because Owin is used instead of a decent DI container, the MVC pipeline requires a default constructor, so checking for zero and a service locator is necessary. How MVC decides which constructor to use is not clear to me. But I found that usermanager was sometimes introduced and would be null in other scenarios. Probably because the owin context in most cases is only available after creating the account controller.
As long as the template works out of the box, it really moves my eyebrows, just like it moves. So I went with a clean implementation of a decent DI container and got the deletion of most of the owin service service information.
If you are interested, you can find my solution here where I used Simple Injector . And there are solutions for other DI containers here
source share