Table of Contents

Class ObjectContainerExtensions

Namespace
CSF.Screenplay
Assembly
CSF.Screenplay.ReqnrollPlugin.dll

Extension methods for the Reqnroll/SpecFlow "BoDi" DI container.

public static class ObjectContainerExtensions
Inheritance
ObjectContainerExtensions
Inherited Members

Methods

ToServiceCollection(IObjectContainer)

Gets an adapter object which permits limited use of the BoDi IObjectContainer as if it were an IServiceCollection.

public static IServiceCollection ToServiceCollection(this IObjectContainer bodiContainer)

Parameters

bodiContainer IObjectContainer

A Reqnroll/SpecFlow BoDi DI container.

Returns

IServiceCollection

An adapter object which implements some of the functionality of IServiceCollection

Remarks

Note that this is an imperfect solution. The BoDi container shipped with Reqnroll/SpecFlow does not support all the functionality which is expected from IServiceCollection. Many methods of the returned object will throw NotSupportedException if attempts are made to use them (a known LSP violation). Additionally, not all service collection DI behaviour will operate in the same manner when using this adapter. In short "your mileage may vary".

However, for the most simple of usages, this enables the use of "Add to DI" logic which has been crafted for service collection, in such a way that services may be added to the BoDi container without additional logic.

ToServiceProvider(IObjectContainer)

Gets an adapter object which permits the use of the BoDi IObjectContainer as if it were an IServiceProvider.

public static IServiceProvider ToServiceProvider(this IObjectContainer bodiContainer)

Parameters

bodiContainer IObjectContainer

A Reqnroll/SpecFlow BoDi DI container.

Returns

IServiceProvider

An adapter object which implements the functionality of IServiceProvider