GithubHelp home page GithubHelp logo

Comments (6)

304NotModified avatar 304NotModified commented on May 24, 2024 1

I found the issue (I have checked out the repo)

If the dependency isn't found, you will get this nasty exception.

So:

namespace SolidToken.SpecFlow.DependencyInjection.Tests
{
    public static class TestDependencies
    {
        [ScenarioDependencies]
        public static IServiceCollection CreateServices()
        {
            var services = new ServiceCollection();

            //// Add test dependencies
            //services.AddTransient<ITestService, TestService>();

            //// ContextInjectionScope (by using AddScoped instead of AddTransient, the context will be scoped to the Feature across bindings)
            //services.AddScoped<TestContext>();

            //// NOTE: This line is essential so that Microsoft.Extensions.DependencyInjection knows
            //// about the SpecFlow bindings (something normally BoDi does automatically).
            //// TODO: Find out if we can make this part of the Plugin
            //foreach (var type in typeof(TestDependencies).Assembly.GetTypes().Where(t => Attribute.IsDefined(t, typeof(BindingAttribute))))
            //{
            //    services.AddSingleton(type);
            //}

            return services;
        }
    }
}

Will demo the issue

from specflow.dependencyinjection.

mbhoek avatar mbhoek commented on May 24, 2024

Let me investigate and I will get back to you.

from specflow.dependencyinjection.

304NotModified avatar 304NotModified commented on May 24, 2024

FYI:

 <TargetFramework>netcoreapp2.1</TargetFramework>

tried also static class, but that won't help either.

The big difference is here (I think), that we're using MSTest and not xUnit

from specflow.dependencyinjection.

mbhoek avatar mbhoek commented on May 24, 2024

Is it possible that you have not registered any bindings (yet)?

For example, if you look at DependencyInjectionPluginSteps.cs you will notice the [Binding] tag that will bind the code to the SpecFlow Feature file.

Currently the plugin requires you to register all the bindings/step definitions (otherwise the DI framework can't find them). So your initialisation code should look like:

  var services = new ServiceCollection();

  foreach (var type in typeof(TestDependencies).Assembly.GetTypes().Where(t => Attribute.IsDefined(t, typeof(BindingAttribute))))
  {
      services.AddSingleton(type);
  }

  return services;

Although this is in the README.md, I don't think it is very intuitive and I want to solve it as part of issue #7 but haven't landed on a solution yet.

from specflow.dependencyinjection.

304NotModified avatar 304NotModified commented on May 24, 2024

ow yes indeed. I missed that! That's the fix.

Would be great if we could make that optional.

from specflow.dependencyinjection.

304NotModified avatar 304NotModified commented on May 24, 2024

@mbhoek check #25 :)

This could be closed.

from specflow.dependencyinjection.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.