Hi, I have been getting the following error in my dev azure pipeline.
'Congresso.Documents.DocumentManager' is waiting for the following dependencies:
Service 'Microsoft.AspNetCore.SignalR.IHubContext`1[[Congresso.Documents.DocumentHub, Congresso.Core, Version=12.0.0.0, Culture=neutral, PublicKeyToken=null]]' which was not registered.
at Castle.MicroKernel.Handlers.DefaultHandler.AssertNotWaitingForDependency() at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernelByType(CreationContext context, ComponentModel model, DependencyModel dependency) at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateConstructorArguments(ConstructorCandidate constructor, CreationContext context) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext context) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context) at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden) at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy) at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernelByType(CreationContext context, ComponentModel model, DependencyModel dependency) at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateConstructorArguments(ConstructorCandidate constructor, CreationContext context) at Castle.Windsor.MsDependencyInjection.MsScopedLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy) at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, Arguments additionalArguments, IReleasePolicy policy, Boolean ignoreParentContext) at Castle.Windsor.MsDependencyInjection.ScopedWindsorServiceProvider.GetServiceInternal(Type serviceType, Boolean isOptional) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.AbpZeroIdentityBuilderExtensions.<>c__DisplayClass0_0
1.<AddAbpTenantManager>b__0(IServiceProvider provider) at Castle.MicroKernel.ComponentActivator.FactoryMethodActivator
1.Instantiate(CreationContext context) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context) at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden) at Castle.Windsor.MsDependencyInjection.MsScopedLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy) at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, Arguments additionalArguments, IReleasePolicy policy, Boolean ignoreParentContext) at Abp.Events.Bus.EventBus.TriggerHandlingException(IEventHandlerFactory handlerFactory, Type eventType, IEventData eventData, List`1 exceptions) at Abp.Events.Bus.EventBus.Trigger(Type eventType, Object eventSource, IEventData eventData) at Abp.Events.Bus.Entities.EntityChangeEventHelper.TriggerEventWithEntity(Type genericEventType, Object entity, Boolean triggerInCurrentUnitOfWork) at Abp.Events.Bus.Ent
[AbpAuthorize] public class DocumentManager : CongressoDomainServiceBase, IDocumentManager {
private readonly IHubContext<DocumentHub> _documentHub;
public DocumentManager(
IHubContext<DocumentHub> documentHub,
)
{
_documentHub = documentHub;
}
public class DocumentHub : Hub
{
}
}
Any suggestions?
Thanks!
8 Answer(s)
-
0
Hi @Astech,
Did you add your hub to endpoints?
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { // Other middleware... app.UseEndpoints(endpoints => { endpoints.MapHub<DocumentHub>("/documentHub"); }); }
-
0
Hi,
Yes I already have it added in my startup. The other ones don't seem to be erroring.
app.UseEndpoints(endpoints => { endpoints.MapHub<AbpCommonHub>("/signalr"); endpoints.MapHub<ChatHub>("/signalr-chat"); endpoints.MapHub<AgendaHub>("/signalr-agenda"); endpoints.MapHub<MinuteHub>("/signalr-minute"); endpoints.MapHub<DocumentHub>("/signalr-document-conversion"); });
-
0
Hi @Astech,
Could you share your
DocumentHub.cs
?Also, you can check for this document. https://aspnetboilerplate.com/Pages/Documents/SignalR-Integration
-
0
Hi,
using Microsoft.AspNetCore.SignalR; namespace Congresso.Documents { public class DocumentHub : Hub { } }
I did check the link to ensure that the necessary packages are also installed.
-
0
Hi @Astech,
You can add dependency with following interface.
using Microsoft.AspNetCore.SignalR; namespace Congresso.Documents { public class DocumentHub : Hub, ITransientDependency { } }
-
0
Seems to be an issue when trying to write & run tests (in the .Test project), that access services that use a hub
I'm assuming the startup.cs from the MVC project does not get run when the tests run so how can we ensure these dependencies are registered within the .Test project in the same way they are within the .Mvc project like below:
app.UseEndpoints(endpoints => { endpoints.MapHub<AbpCommonHub>("/signalr"); endpoints.MapHub<ChatHub>("/signalr-chat"); endpoints.MapHub<AgendaHub>("/signalr-agenda"); endpoints.MapHub<MinuteHub>("/signalr-minute"); endpoints.MapHub<DocumentHub>("/signalr-document-conversion"); });
There appears to be no startup.cs file in the .Test project to try the same code. Trying to register the Hub in the same way as we register services in the test project:
public Security_Tests() { _documentHub = Resolve<IHubContext<DocumentHub>>(); _documentsAppService = Resolve<IDocumentsAppService>(); // Service that uses the DocumentHub }
Results in:
Abp.AbpException : Can not register IHubContext`1. It should be a non-abstract class. If not, it should be registered before.
Many thanks
-
0
Hi @Astech,
You can mock your
DocumentHub
for unit testing._documentHub = Substitute.For<IHubContext<DocumentHub>>();
-
0
Many thanks m.aliozkaya
This has resolved the issue. To help anyone else, this is the complete code segment for unit testing an app service that utilies SignalR:
var fakeDocumentHub = Substitute.For<IHubContext<DocumentHub>>(); LocalIocManager.IocContainer.Register(Component.For<IHubContext<DocumentHub>>().Instance(fakeDocumentHub).IsDefault()); var _documentsAppService = Resolve<IDocumentsAppService>();
Do this to get the service instance instead of using Dependency Injection in the unit test class itself.
Thanks again m.aliozkaya