Show / Hide Table of Contents

    Class DefaultCodecFactory

    LUCENENET specific class that implements the default functionality for the ICodecFactory.

    The most common use cases are:

    • Initialize DefaultCodecFactory with a set of CustomCodecTypes.
    • Subclass DefaultCodecFactory and override GetCodec(Type) so an external dependency injection container can be used to supply the instances (lifetime should be singleton). Note that you could alternately use the "named type" feature that many DI containers have to supply the type based on name by overriding GetCodec(String).
    • Subclass DefaultCodecFactory and override GetCodecType(String) so a type new type can be supplied that is not in the Lucene.Net.Codecs.DefaultCodecFactory.codecNameToTypeMap.
    • Subclass DefaultCodecFactory to add new or override the default Codec types by overriding Initialize() and calling PutCodecType(Type).
    • Subclass DefaultCodecFactory to scan additional assemblies for Codec subclasses in by overriding Initialize() and calling ScanForCodecs(Assembly). For performance reasons, the default behavior only loads Lucene.Net codecs.

    To set the ICodecFactory, call SetCodecFactory(ICodecFactory).

    Inheritance
    System.Object
    NamedServiceFactory<Codec>
    DefaultCodecFactory
    Implements
    ICodecFactory
    IServiceListable
    Inherited Members
    NamedServiceFactory<Codec>.m_initializationLock
    NamedServiceFactory<Codec>.EnsureInitialized()
    NamedServiceFactory<Codec>.CodecsAssembly
    NamedServiceFactory<Codec>.IsServiceType(Type)
    NamedServiceFactory<Codec>.GetServiceName(Type)
    NamedServiceFactory<Codec>.GetCanonicalName(Type)
    NamedServiceFactory<Codec>.IsFullyTrusted
    Namespace: Lucene.Net.Codecs
    Assembly: Lucene.Net.dll
    Syntax
    public class DefaultCodecFactory : NamedServiceFactory<Codec>, ICodecFactory, IServiceListable

    Constructors

    | Improve this Doc View Source

    DefaultCodecFactory()

    Creates a new instance of DefaultCodecFactory.

    Declaration
    public DefaultCodecFactory()

    Properties

    | Improve this Doc View Source

    AvailableServices

    Gets a list of the available Codecs (by name).

    Declaration
    public virtual ICollection<string> AvailableServices { get; }
    Property Value
    Type Description
    ICollection<System.String>

    A ICollection{string} of Codec names.

    | Improve this Doc View Source

    CustomCodecTypes

    An array of custom Codec-derived types to be registered. This property can be initialized during construction of DefaultCodecFactory to make your custom codecs known to Lucene.

    These types will be registered after the default Lucene types, so if a custom type has the same name as a Lucene Codec (via CodecNameAttribute) the custom type will replace the Lucene type with the same name.

    Declaration
    public IEnumerable<Type> CustomCodecTypes { get; set; }
    Property Value
    Type Description
    IEnumerable<Type>

    Methods

    | Improve this Doc View Source

    GetCodec(String)

    Gets the Codec instance from the provided name.

    Declaration
    public virtual Codec GetCodec(string name)
    Parameters
    Type Name Description
    System.String name

    The name of the Codec instance to retrieve.

    Returns
    Type Description
    Codec

    The Codec instance.

    | Improve this Doc View Source

    GetCodec(Type)

    Gets the Codec instance from the provided type.

    Declaration
    protected virtual Codec GetCodec(Type type)
    Parameters
    Type Name Description
    Type type

    The of Codec to retrieve.

    Returns
    Type Description
    Codec

    The Codec instance.

    | Improve this Doc View Source

    GetCodecType(String)

    Gets the Codec from the provided name.

    Declaration
    protected virtual Type GetCodecType(string name)
    Parameters
    Type Name Description
    System.String name

    The name of the Codec to retrieve.

    Returns
    Type Description
    Type

    The Codec .

    | Improve this Doc View Source

    Initialize()

    Initializes the codec type cache with the known Codec types. Override this method (and optionally call base.Initialize()) to add your own Codec types by calling PutCodecType(Type) or ScanForCodecs(Assembly).

    If two types have the same name by using the CodecNameAttribute, the last one registered wins.

    Declaration
    protected override void Initialize()
    Overrides
    Lucene.Net.Util.NamedServiceFactory<Lucene.Net.Codecs.Codec>.Initialize()
    | Improve this Doc View Source

    NewCodec(Type)

    Instantiates a Codec based on the provided type.

    Declaration
    protected virtual Codec NewCodec(Type type)
    Parameters
    Type Name Description
    Type type

    The of Codec to instantiate.

    Returns
    Type Description
    Codec

    The new instance.

    | Improve this Doc View Source

    PutCodecType(Type)

    Adds a Codec type to the Lucene.Net.Codecs.DefaultCodecFactory.codecNameToTypeMap, using the name provided in the CodecNameAttribute, if present, or the name of the codec class minus the "Codec" suffix as the name by default.

    Note that if a Codec with the same name already exists in the map, calling this method will update it to the new type.

    Declaration
    protected virtual void PutCodecType(Type codec)
    Parameters
    Type Name Description
    Type codec

    A type that subclasses Codec.

    | Improve this Doc View Source

    ScanForCodecs(Assembly)

    Scans the given assembly for subclasses of Codec and adds their names to the Lucene.Net.Codecs.DefaultCodecFactory.codecNameToTypeMap. Note that names will be automatically overridden if the Codec name appears multiple times - the last match wins.

    Declaration
    protected virtual void ScanForCodecs(Assembly assembly)
    Parameters
    Type Name Description
    Assembly assembly

    The assembly to scan.

    | Improve this Doc View Source

    ScanForCodecs(IEnumerable<Assembly>)

    Scans the given assemblies for subclasses of Codec and adds their names to the Lucene.Net.Codecs.DefaultCodecFactory.codecNameToTypeMap. Note that names will be automatically overridden if the Codec name appears multiple times - the last match wins.

    Declaration
    protected virtual void ScanForCodecs(IEnumerable<Assembly> assemblies)
    Parameters
    Type Name Description
    IEnumerable<Assembly> assemblies

    A list of assemblies to scan. The assemblies will be scanned from first to last, and the last match for each Codec name wins.

    Implements

    ICodecFactory
    IServiceListable
    • Improve this Doc
    • View Source
    Back to top Copyright © 2020 Licensed to the Apache Software Foundation (ASF)