Click or drag to resize

ContravariantRegistrationSource Class

Enables contravariant Resolve() for interfaces that have a single contravariant ('in') parameter.
Inheritance Hierarchy
SystemObject
  Autofac.Features.VarianceContravariantRegistrationSource

Namespace:  Autofac.Features.Variance
Assembly:  Autofac (in Autofac.dll) Version: 4.9.1+831973f4d02fbc619921dfaa8ac0c536f60ae7a3
Syntax
public class ContravariantRegistrationSource : IRegistrationSource

The ContravariantRegistrationSource type exposes the following members.

Constructors
  NameDescription
Public methodContravariantRegistrationSource
Initializes a new instance of the ContravariantRegistrationSource class
Top
Properties
  NameDescription
Public propertyIsAdapterForIndividualComponents
Gets a value indicating whether the registrations provided by this source are 1:1 adapters on top of other components (e.g., Meta, Func, or Owned).
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodRegistrationsFor
Retrieve registrations for an unregistered service, to be used by the container.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Examples
interface IHandler<in TCommand>
{
    void Handle(TCommand command);
}

class Command { }

class DerivedCommand : Command { }

class CommandHandler : IHandler<Command> { ... }

var builder = new ContainerBuilder();
builder.RegisterSource(new ContravariantRegistrationSource());
builder.RegisterType<CommandHandler>();
var container = builder.Build();
// Source enables this line, even though IHandler<Command> is the
// actual registered type.
var handler = container.Resolve<IHandler<DerivedCommand>>();
handler.Handle(new DerivedCommand());
See Also