Base solution for your next web application
Open Closed

Tests Failing - Custom Dependency Injection for Base Test Project #12004


User avatar
0
naurinrr created

``Need some help changing the base test project. Our product has a requirement to inject the IWebHostEnvironment into CoreModule to conditionally set dependency resolution for an interface. We read the config to say whether to resolve to one type of provider or another. This works well except all the out-of-the-box tests (and new ones) are failing as I am not sure how to proceed.

Source: EditionAppService_Tests.cs line 31 Duration: 1 ms

Message:  Castle.MicroKernel.Handlers.HandlerException : Can't create component 'Project.Test.TestCoreModule' as it has dependencies to be satisfied.

'Project.Test.TestCoreModule' is waiting for the following dependencies:

  • Service 'Microsoft.AspNetCore.Hosting.IWebHostEnvironment' which was not registered.

Stack Trace:  DefaultHandler.AssertNotWaitingForDependency() DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired) AbstractHandler.Resolve(CreationContext context) DefaultKernel.ResolveComponent(IHandler handler, Type service, Arguments additionalArguments, IReleasePolicy policy, Boolean ignoreParentContext) IKernelInternal.Resolve(Type service, Arguments arguments, IReleasePolicy policy, Boolean ignoreParentContext) DefaultKernel.Resolve(Type service, Arguments arguments) WindsorContainer.Resolve(Type service) IocManager.Resolve(Type type) AbpModuleManager.CreateModules(ICollection1 moduleTypes, List1 plugInModuleTypes) AbpModuleManager.LoadAllModules() AbpModuleManager.Initialize(Type startupModule) AbpBootstrapper.Initialize() AbpIntegratedTestBase1.InitializeAbp() AbpIntegratedTestBase1.ctor(Boolean initializeAbp, IIocManager localIocManager) AppTestBase`1.ctor() line 30 AppTestBase.ctor() EditionAppService_Tests.ctor() line 22 RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Our product has a requirement to inject the IWebHostEnvironment into CoreModule to conditionally set dependency resolution for an interface

    Could you share how do you register the interface ? Normally, you shouldn't use IWebHostEnvironment in the CoreModule.