Table of Contents

Interface ICast

Namespace
CSF.Screenplay
Assembly
CSF.Screenplay.Abstractions.dll

A combined registry and factory for Actor instances, useful when coordinating multiple actors across a IPerformance

public interface ICast : IHasServiceProvider, IHasPerformanceIdentity
Inherited Members
Extension Methods

Remarks

The cast is a strongly recommended component of Screenplay logic. It is used to manage Actor objects for the duration of a IPerformance. Cast objects are always scoped to a IPerformance and have the same lifetime. Any actors created or tracked by a cast will also automatically share this lifetime.

In terms of design patterns, the cast operates as both a registry: https://martinfowler.com/eaaCatalog/registry.html and as a factory: https://en.wikipedia.org/wiki/Factory_method_pattern for actors. During the cast's lifetime, subsequent calls to an overload of GetActor using the same actor/persona name will return the instance of Actor as was created the first time the method was called with that name. A cast, and the actors managed by a cast, are independent per IPerformance, though.

Developers are strongly advised to configure their actors via classes which derive from IPersona. This allows for sharing of common actor-setup logic such as abilities.

In a Screenplay the cast is a dependency-injectable service which may be used within your performances.

Methods

GetActor(IPersona)

Gets a single Actor based upon a persona, creating them if they do not already exist in the cast.

Actor GetActor(IPersona persona)

Parameters

persona IPersona

The persona from which to get an actor

Returns

Actor

An actor of the specified name, either an existing instance or a newly-created actor.

Remarks

This method will create the actor within the current cast, using the persona as a factory, if they do not already exist. Alternatively, this method will return the existing actor, if they already exist in the cast, matched using the IPersona's Name.

Actor names are matched using a case-insensitive invariant culture string comparison. Cast implementations should match an existing actor if the specified persona name differs only in case.

Consider using GetActor<TPersona>(ICast) instead of this method; the generic version takes care of resolving the persona instance from dependency injection for you.

See Also

GetActor(string)

Gets a single Actor by their name, creating them if they do not already exist in the cast.

Actor GetActor(string name)

Parameters

name string

The name of the actor to get

Returns

Actor

An actor of the specified name, either an existing instance or a newly-created actor.

Remarks

This method will create the actor within the current cast, if they do not already exist. Alternatively, this method will return the existing actor, if they already exist in the cast.

Actor names are matched using a case-insensitive invariant culture string comparison. Cast implementations should match an existing actor if the specified name differs only in case.

If you make use of a same-named actor across multiple performances then it is highly recommended to use personas in order to consistently define the actor's attributes and abilities. You would then use the overload of this method which uses that persona to define the actor.

See Also

See Also