-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dependency injection of custom IdentityUser class #11232
Comments
@HaoK thoughts? |
Including the working code isn't as helpful as including the code that is causing the error, can you include that as well? |
@HaoK Hi, yes sure.
|
Does everything work if you add a reference to the unreferenced assembly that contains the types? |
It does work if called from ConfigureServices method.
|
OK I assume now it is dependency injection issue after all. GetService returns null.
|
I have managed to solve the issue. For example:
The same works for UserManager class, where we need to extend the built in UserManager class as partial class and implement custom IUserManager interface. In that case we are able to use custom ApplicationUser class. |
Hi,
I need help understanding how this could be done.
What I am trying to achieve is dependency injection of UserManager service in unreferenced assembly from main project. Everything is working if built in IdentityUser is used as type, but when trying to do the same with custom one, it can't build the service, no mater what I try.
Here is the execution chain with the built in IdentityUser class that works fine:
Executable project startup class, ConfigureServices method call:
Executable project is referencing library assembly (application layer) containing implementation of LoadIdentityService method.
LoadIdentityService then loads dynamically another library assembly, containing IIdentityService implementation (infrastructure layer) and calls RegisterIdentityService interface method.
And finally infrastructure layer is implementing identityservice self registration into main project services collection.
The end user of this dependency injection is the identityservice itself, trying to use the service in its command handler implementation.
If used instead of IdentityUser with custom ApplicationUser (implemented at identity service assembly) it throws this exception:
The text was updated successfully, but these errors were encountered: