I'm running into an issue with the inclusion of resolution and initialization of ChatUserStateWatcher
in the CoreModule. I am trying to construct tests for services I am adding for my application against a database that I am maintaining as a separate DbContext. As part of this, I have to initialize the EntityFrameworkCore module, which depends on CoreModule. When the system is initializing the CoreModule, I am getting an error in the "PostInitialize()" code when it reaches the "ChatUserStateWatcher"
resolution:
<br>
public override void PostInitialize()
{
IocManager.RegisterIfNot<IChatCommunicator, NullChatCommunicator>();
IocManager.Register<IUserDelegationConfiguration, UserDelegationConfiguration>();
IocManager.Resolve<ChatUserStateWatcher>().Initialize();
IocManager.Resolve<AppTimes>().StartupTime = Clock.Now;
}
Error: <br>
Message:
Castle.MicroKernel.Handlers.HandlerException : Can't create component 'NexusApps.Authorization.Users.UserManager' as it has dependencies to be satisfied.
'NexusApps.Authorization.Users.UserManager' is waiting for the following dependencies:
- Service 'Microsoft.Extensions.Options.IOptions`1[[Microsoft.AspNetCore.Identity.IdentityOptions, Microsoft.Extensions.Identity.Core, Version=3.1.6.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]]' which was not registered.
- Service 'Microsoft.AspNetCore.Identity.IPasswordHasher`1[[NexusApps.Authorization.Users.User, NexusApps.Core, Version=9.0.0.0, Culture=neutral, PublicKeyToken=null]]' which was not registered.
- Service 'System.Collections.Generic.IEnumerable`1[[Microsoft.AspNetCore.Identity.IUserValidator`1[[NexusApps.Authorization.Users.User, NexusApps.Core, Version=9.0.0.0, Culture=neutral, PublicKeyToken=null]], Microsoft.Extensions.Identity.Core, Version=3.1.6.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]]' which was not registered.
- Service 'System.Collections.Generic.IEnumerable`1[[Microsoft.AspNetCore.Identity.IPasswordValidator`1[[NexusApps.Authorization.Users.User, NexusApps.Core, Version=9.0.0.0, Culture=neutral, PublicKeyToken=null]], Microsoft.Extensions.Identity.Core, Version=3.1.6.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]]' which was not registered.
- Service 'Microsoft.AspNetCore.Identity.ILookupNormalizer' which was not registered.
- Service 'Microsoft.AspNetCore.Identity.IdentityErrorDescriber' which was not registered.
- Service 'System.IServiceProvider' which was not registered.
- Service 'Microsoft.Extensions.Logging.ILogger`1[[NexusApps.Authorization.Users.UserManager, NexusApps.Core, Version=9.0.0.0, Culture=neutral, PublicKeyToken=null]]' which was not registered.
- Service 'NexusApps.Authorization.Roles.RoleManager' which was registered but is also waiting for dependencies.
'NexusApps.Authorization.Roles.RoleManager' is waiting for the following dependencies:
- Service 'System.Collections.Generic.IEnumerable`1[[Microsoft.AspNetCore.Identity.IRoleValidator`1[[NexusApps.Authorization.Roles.Role, NexusApps.Core, Version=9.0.0.0, Culture=neutral, PublicKeyToken=null]], Microsoft.Extensions.Identity.Core, Version=3.1.6.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]]' which was not registered.
- Service 'Microsoft.AspNetCore.Identity.ILookupNormalizer' which was not registered.
- Service 'Microsoft.AspNetCore.Identity.IdentityErrorDescriber' which was not registered.
- Service 'Microsoft.Extensions.Logging.ILogger`1[[NexusApps.Authorization.Roles.RoleManager, NexusApps.Core, Version=9.0.0.0, Culture=neutral, PublicKeyToken=null]]' which was not registered.
When I skip this statement, my test will run fine, without this error. I introduced a bool property in the <AZNProject>CoreModule.cs that allows me to control skipping this when I'm initialiing my testing module. However, I'm concerned that as I customize the AspNetZero-supplied code, it is going to get more difficult to merge in changes as new versions are released.
Will you add an issue in your development queue to change how the resolution/instantiation of the ChatUserStateWatcher class is managed? It seems to me that it should only be when the ChatService is actually needed. I don't want to have to get the entire AspNetZero schema/services instantiated just to test my added service.
3 Answer(s)
-
0
Hi,
Do you have this line in your project https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/test/MyCompanyName.AbpZeroTemplate.Test.Base/DependencyInjection/ServiceCollectionRegistrar.cs#L39 and does it run when you execute your tests ?
-
0
At the time I posted, I did not have a ServiceCollectionRegistrar in my test module. I added one that mimics the one provided with the AspnetZero project, and removed the flag I had added to skip the Resolve<ChatUserStateWatcher>, and it works now.
Is there someplace that explains what adding this does in the dependency injection process? I'd like to better understand the dependency injection system in Aspnetzero.
-
0
Hi,
It basically registers
IPasswordHasher
and several other classes used by ASP.NET Core Identity.