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).
Inherited Members
Namespace: Lucene.Net.Codecs
Assembly: Lucene.Net.dll
Syntax
public class DefaultCodecFactory : NamedServiceFactory<Codec>, ICodecFactory, IServiceListable
Constructors
| Improve this Doc View SourceDefaultCodecFactory()
Creates a new instance of DefaultCodecFactory.
Declaration
public DefaultCodecFactory()
Properties
| Improve this Doc View SourceAvailableServices
Gets a list of the available Codecs (by name).
Declaration
public virtual ICollection<string> AvailableServices { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.ICollection<System.String> | A ICollection{string} of Codec names. |
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 |
---|---|
System.Collections.Generic.IEnumerable<System.Type> |
Methods
| Improve this Doc View SourceGetCodec(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. |
GetCodec(Type)
Gets the Codec instance from the provided type
.
Declaration
protected virtual Codec GetCodec(Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The System.Type of Codec to retrieve. |
Returns
Type | Description |
---|---|
Codec | The Codec instance. |
GetCodecType(String)
Gets the Codec System.Type from the provided name
.
Declaration
protected virtual Type GetCodecType(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the Codec System.Type to retrieve. |
Returns
Type | Description |
---|---|
System.Type | The Codec System.Type. |
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
NewCodec(Type)
Instantiates a Codec based on the provided type
.
Declaration
protected virtual Codec NewCodec(Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The System.Type of Codec to instantiate. |
Returns
Type | Description |
---|---|
Codec | The new instance. |
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 |
---|---|---|
System.Type | codec | A type that subclasses Codec. |
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 |
---|---|---|
System.Collections.Generic.IEnumerable<System.Reflection.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. |
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 |
---|---|---|
System.Reflection.Assembly | assembly | The assembly to scan. |