Skip to main content

replace dependency in autofac BeforeFeature/BeforeScenario

Comments

3 comments

  • Andreas Willich

    I am not sure where you have a problem, could you elaborate a little bit more?

    0
  • Eliav Ran

    in the given i would like to change the mock class to simulate success flow or failed and have different scenarios
    something along the line of

    [Given(@"Set mock class")]
    public void SetMockClass()
    {
        var autofacBuilder = new ContainerBuilder();
        autofacBuilder.RegisterType<TestMock>().As<IRealClass>().SingleInstance();
        var fakeContainer = autofacBuilder.build();
        fakeContainer.Update(realContainer);
    }

    that way i can update the original container to have different dependencies then in the initial registration 

    0
  • Andreas Willich

    I looked at the code at it is not possible to change the registrations after the ScenarioDependencies method is not possible.

    The only workaround I can think about is to use a lambda registration and return different implementations depending on some input value.

    Autofac documentation is here for it: https://autofac.readthedocs.io/en/latest/register/registration.html#selection-of-an-implementation-by-parameter-value

    0

Please sign in to leave a comment.

Powered by Zendesk