Skip to main content

Binder<TContract>

A class in Alta.LifetimeScopes, Alta.ATT.LifetimeScopes.

Fluent helper for registering a type in a VContainer container, made by container.Bind<TContract>(). Registers as a singleton by default and picks up VContainer entry point interfaces (like ITickable) by itself.

Constructors​

MemberWhat it is
Binder(IContainerBuilder container)Creates a Binder from container.

Fields​

1 private and internal field
MemberWhat it is
private const Lifetime DefaultLifetimeConstant: singleton.

Properties​

6 private and internal properties
MemberWhat it is
private List<Type> BoundTypes { get; }The contract types the result is registered as. Starts with TContract.
private IContainerBuilder Container { get; }The container builder this binder registers into.
private bool HasEntryPoints { get; set; }Set when the result or a bound type is a VContainer entry point, so the entry point dispatcher gets registered.
private Lifetime Lifetime { get; set; }The lifetime the registration uses.
internal Binder<TContract> RegistrationBuilder { get; }The builder registered with the container. It builds the final registration from this binder's settings.
private Type ResultType { get; set; }The concrete type resolved for the contract, set by To.

Methods​

MemberWhat it is
Binder<TContract> And<TAdditionalContract>()Also registers the result under another contract type.
Binder<TContract> AsScoped()Registers with scoped lifetime.
Binder<TContract> AsSingleton()Registers with singleton lifetime (the default).
Binder<TContract> AsTransient()Registers with transient lifetime, a new instance each time it is resolved.
Binder<TContract> To<TResult>()Sets the concrete type to resolve. The overload taking an instance registers that existing object instead.
Binder<TContract> To<TResult>(TResult instance)Sets the concrete type to resolve. The overload taking an instance registers that existing object instead.
3 private and internal methods
MemberWhat it is
private void BindToType(Type type)Adds a contract type to the bound types if it isn't there yet.
private void RegisterAnyValidEntryPoints()Checks the result type and bound types for entry point interfaces and binds any it finds. Called when the registration is built.
private void RegisterEntryPointInType(Type type)Binds any VContainer entry point interfaces a type implements, and notes that entry points exist.

Used in​

Members of other types that take, return or hold a Binder&lt;TContract>: