Class ServiceCollectionAdapter
- Namespace
- CSF.Screenplay
- Assembly
- CSF.Screenplay.SpecFlowPlugin.dll
Adapter class which allows a SpecFlow/BoDi IObjectContainer
to be used as an IServiceCollection.
public class ServiceCollectionAdapter : IServiceCollection, IList<ServiceDescriptor>, ICollection<ServiceDescriptor>, IEnumerable<ServiceDescriptor>, IEnumerable
- Inheritance
-
ServiceCollectionAdapter
- Implements
- Inherited Members
- Extension Methods
Remarks
This adapter class is highly limited and supports only a tiny subset of IServiceCollection's functionality. For many methods, and the indexer for ServiceDescriptor, it will raise NotSupportedException. The only functionality supported is IsReadOnly and Add(ServiceDescriptor).
Constructors
ServiceCollectionAdapter(IObjectContainer)
Initialises an instance of ServiceCollectionAdapter.
public ServiceCollectionAdapter(IObjectContainer wrapped)
Parameters
wrapped
IObjectContainerThe BoDi object container
Exceptions
- ArgumentNullException
If
wrapped
is null.
Properties
Count
Not supported, always returns zero.
public int Count { get; }
Property Value
IsReadOnly
Partially supported, always returns false
public bool IsReadOnly { get; }
Property Value
this[int]
Not supported; always throws NotSupportedException.
public ServiceDescriptor this[int index] { get; set; }
Parameters
index
int
Property Value
Exceptions
- NotSupportedException
Always thrown
Methods
Add(ServiceDescriptor)
Partially-supported, will add the specified service descriptor to the current object container.
public void Add(ServiceDescriptor item)
Parameters
item
ServiceDescriptorThe service descriptor
Remarks
This method supports only transient or singleton services. If the Lifetime present on the item specified is Scoped then the service descriptor will not be added and will be silently ignored.
In reality, the Specflow BoDi object container only really supports singleton services at this level. So, any services added as Transient will actually become singletons here. Whilst the BoDi container does support scoped services, they must be added directly to the scope instance and cannot be added in advance.
Exceptions
- ArgumentNullException
If
item
is null.- ArgumentException
If the
item
has a nullServiceType.
Clear()
Not supported; always throws NotSupportedException.
public void Clear()
Exceptions
- NotSupportedException
Always thrown
Contains(ServiceDescriptor)
Not supported; always throws NotSupportedException.
public bool Contains(ServiceDescriptor item)
Parameters
item
ServiceDescriptor
Returns
Exceptions
- NotSupportedException
Always thrown
CopyTo(ServiceDescriptor[], int)
Not supported; always throws NotSupportedException.
public void CopyTo(ServiceDescriptor[] array, int arrayIndex)
Parameters
array
ServiceDescriptor[]arrayIndex
int
Exceptions
- NotSupportedException
Always thrown
GetEnumerator()
Not supported; always throws NotSupportedException.
public IEnumerator<ServiceDescriptor> GetEnumerator()
Returns
Exceptions
- NotSupportedException
Always thrown
IndexOf(ServiceDescriptor)
Not supported; always throws NotSupportedException.
public int IndexOf(ServiceDescriptor item)
Parameters
item
ServiceDescriptor
Returns
Exceptions
- NotSupportedException
Always thrown
Insert(int, ServiceDescriptor)
Not supported; always throws NotSupportedException.
public void Insert(int index, ServiceDescriptor item)
Parameters
index
intitem
ServiceDescriptor
Exceptions
- NotSupportedException
Always thrown
Remove(ServiceDescriptor)
Not supported; always throws NotSupportedException.
public bool Remove(ServiceDescriptor item)
Parameters
item
ServiceDescriptor
Returns
Exceptions
- NotSupportedException
Always thrown
RemoveAt(int)
Not supported; always throws NotSupportedException.
public void RemoveAt(int index)
Parameters
index
int
Exceptions
- NotSupportedException
Always thrown