Closed Pr1vEsc closed 6 years ago
As UserManager needs a connection to the database, and that's scoped to per request you're not going to be able to do this, even if you did manage to put your utility class in DI.
Remember DI can only inject into other classes in DI.
If all you want this that function why not consider an extension method?
I ended up using DI in my Controller and loading the info into a ViewBag and then referencing it in the View.
Thanks for suggestion.
Steve
That would seem the safest way. Whilst you can DI into views, it makes a lot of people who care about purity unhappy :)
I did not know you can DI into View. Thanks for the suggestion because that was even easier. Learn new things every day.
@inject UserManager
Much appreciated. Steve
I am trying to get a list of Users back from UserManager but I am having issues understanding how this is accomplished.
public class Util { private readonly UserManager _userManager;
However when I create a instance of the Utility class it wants me to pass in a UserManager context and I thought DI would take care of this.
Thoughts Steve