Skip to content
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

Autofac.Core.RegisComponentNotRegisteredException : The requested service 'Reqnroll.FeatureContext' has not been registered. #6

Open
Antwane opened this issue Dec 3, 2024 · 5 comments

Comments

@Antwane
Copy link

Antwane commented Dec 3, 2024

Hello there, I recently started a new project with Reqnroll & Autofac and I wanted to include ReportPortal to it. The problem is as soon as I added the nuget to the project, it stops working. I get the following exception

Autofac.Core.Registration.ComponentNotRegisteredException : The requested service 'Reqnroll.FeatureContext' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.

Steps to Reproduce:

  1. Create a new project using Reqnroll template
  2. Add Reqnroll.Autofac 2.2.1
  3. Add ReportPortal.Reqnroll 1.2.0
  4. Add a GlobalHooks.cs file for your dependency injection with 2 sections: [GlobalDependencies] and [ScenarioDependencies]
  5. Debug "Add two numbers" test case, it fail with the above exception, it won't reach the test.

Thanks,

@adc-cjewett
Copy link

Did you find a solution for this? Seeing a similar error after introducing the ReportPortal.Reqnroll package and the ReportPortal.json
Autofac.Core.Registration.ComponentNotRegisteredException: The requested service 'ReportPortal.ReqnrollPlugin.ReportPortalHooks' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.

@adc-cjewett
Copy link

We solved this problem by using reflection to register the ReportPortalHooks.

namespace PlaywrightTests
{
    public static class TestStartup
    {
        [ScenarioDependencies]
        public static void CreateServices(ContainerBuilder builder)
        {
            builder.RegisterReqnroll();
        }

        private static void RegisterReqnroll(this ContainerBuilder builder)
        {
            string assemblyQualifiedName =
                "ReportPortal.ReqnrollPlugin.ReportPortalHooks, ReportPortal.ReqnrollPlugin"; // Fully qualified name of the internal class, including the namespace and assembly
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
            Type hooksType = Type.GetType(assemblyQualifiedName, throwOnError: false);
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.

            if (hooksType != null)
            {
                // Use BindingFlags to access non-public constructors
                var instance = Activator.CreateInstance(hooksType, nonPublic: true);

                if (instance != null)
                {
                    builder.RegisterInstance(instance).AsSelf().SingleInstance();
                }
            }
        }
    }
}

@Antwane
Copy link
Author

Antwane commented Jan 2, 2025

Hey There, thanks very much for the suggestion. Unfortunately it doesn't seem to fix my issue. In my scenario the exception is thrown before the "ScenarioDependencies" hooks is called.

@nvborisenko
Copy link
Member

Can someone to create simple minimal project to reproduce the issue? I will help.

@Antwane
Copy link
Author

Antwane commented Jan 22, 2025

Hi There, yes absolutely

https://github.com/Antwane/Reqnroll.ReportalPortal.ReproProject

I created that one a while back but the problems persists.

Any feedback is appreciated,

Thanks very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants