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 dependencies are not resolved in BeforeTestRun when the dependencies are registered as Global Dependencies #2734

Open
manikandantk88 opened this issue Jan 25, 2024 · 1 comment
Labels

Comments

@manikandantk88
Copy link

SpecFlow Version

3.9.0

Which test runner are you using?

xUnit

Test Runner Version Number

2.5.1

.NET Implementation

.NET 6.0

Project Format of the SpecFlow project

Classic project format using <PackageReference> tags

.feature.cs files are generated using

SpecFlow.Tools.MsBuild.Generation NuGet package

Test Execution Method

Visual Studio Test Explorer

SpecFlow Section in app.config or content of specflow.json

No response

Issue Description

Hi,
I am using Autofac plugin for dependency injection. I am trying to register dependencies in a static method tagged with GlobalDependencies by following the Autofac Document

The registered dependencies are not getting resolved in BeforeTestRun

Steps to Reproduce

public sealed class GlobalHooks
{
    [GlobalDependencies]
    public static void CreateGlobalContainer(ContainerBuilder containerBuilder)
    {
        DependencyInjector.RegisterGlobalDependencies(containerBuilder);
        Log.Logger = new LoggerConfiguration()
            .WriteTo.Console()
            .CreateLogger();
    }
    [BeforeTestRun]
    public static void InitializeTestRun(ITestLogger testLogger)
    {
        testLogger.Log("Log is from before test run");
    }
}
public static class DependencyInjector
{
    public static void RegisterGlobalDependencies(ContainerBuilder containerBuilder)
    {
        var services = RegisterServicesWithSerivceCollection();
        containerBuilder.Populate(services);
    }

    private static IServiceCollection RegisterServicesWithSerivceCollection()
    {
        var services = new ServiceCollection();
        services.AddTransient<ITestLogger, TestLogger>();
        return services;
    }
}

Link to Repro Project

No response

@rbeattie-ssi
Copy link

Is this a sequence of events problem for you (GlobalDependenies runs but after BeforeTestRun) or GlobalDependencies doesn't run at all? For me I don't see GlobalDependencies fire at all while ScenarioDependencies fires as expected.

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

No branches or pull requests

2 participants