Giter Club home page Giter Club logo

specflowmicrosoftdependencyinjection's Introduction

AdCodicem.SpecFlow.MicrosoftDependencyInjection

AdCodicem.SpecFlow.MicrosoftDependencyInjection is a SpecFlow plugin that enables to use Microsoft.Extensions.DependencyInjection for resolving test dependencies. It's based on Gáspár Nagy's SpecFlow.Autofac plugin.

Currently supports :

  • SpecFlow 3.0 or above
  • Microsoft.Extensions.DependencyInjection 2.1 or above

License: Apache

NuGet: Nuget

Build Status Build Status

Release Status Release Status

Why this plugin ?

I created this plugin for Specflow because most of my projects use the plain Microsoft.Extensions.DependencyInjection for injecting dependency. If you've already familiar why ASP.Net Core dependency injection, you won't be lost with this plugin 😉.

Usage

Typical usage

Install plugin from NuGet into your SpecFlow project.

PM> Install-Package AdCodicem.SpecFlow.MicrosoftDependencyInjection

Create a non-static class somewhere in the SpecFlow project implementing the IServicesConfigurator interface. Configure the dependencies within the method.

You don't have to register the step definition classes as it's already done by this plugin.

⚠️ Do not use other dependency injection plugin for SpecFlow.

A typical dependency configuration class probably looks like this :

public class Startup : IServicesConfigurator
{
    /// <inheritdoc />
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddTransient<ICalculator, Calculator>();
    }
}

Delegate the resolution to the original container

Since v1.1.0 you can instruct the service collection to use the dependencies registered automatically by Specflow.

public class Startup : IServicesConfigurator
{
    /// <inheritdoc />
    public void ConfigureServices(IServiceCollection services)
    {
        services
            // ITestOutputHelper is automatically registered by Specflow when using xUnit runner
            .AddDelegated<ITestOutputHelper>()
            // Calculator can use ITestOutputHelper as it's registered above to delegate the resolution to the original container
            .AddTransient<ICalculator, Calculator>();
    }
}

To register a delegated service, simply add the following call in configuration pipeline: AddDelegated<TService>(). The service resolution is delegated to the original container used by Specflow.

Release History

v1.1.1

  • Fix: Added Intellisense documentation

v1.1.0

  • Feature: Allow the delegation of the resolution of some services to the original Specflow dependency injection. The delegated services must be registered like this: services.AddDelegated<ITestOutputHelper>().

v1.0.2

  • Fix: Registered services are now disposed if they're disposable.

v1.0.1

  • Initial release.
  • Increased minimal Microsoft.Extensions.DependencyInjection version to 2.1.0 to prevent MissingMethodException issue when using an higher version of the NuGet.

specflowmicrosoftdependencyinjection's People

Contributors

adcodicem avatar

Watchers

 avatar

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.