3

I'm struggling with a problem when using DependencyResolver.GetService() inside a method called from UserManager.CreateAsync() in AspNet.Identity.

I've added a UserProfile class to the AspNetUser according to this article.

All works fine but when creating a new user it tries to create my UserProfile entity as well and inside this I have an attribute [CheckIfExists] checks if the UserProfile already exists. In this method, let's call it CheckIfExists(), I use DependencyResolver.GetService() to resolve my interface ICheckIfExists to the "concreate" class CheckIfExists. This fails since the current thread is not part of the HttpContext (since it's running in CreateAsync():s thread).

Has anyone encountered this problem? Is there a solution for it? I'm using StructureMap for IoC.

Electric Sheep
  • 3,867
  • 1
  • 29
  • 38
  • 1
    This is orthogonal to your question but if you're using your IoC container as a service locator you're not really doing IoC. – Casey Apr 04 '14 at 03:32

0 Answers0