public ServiceProviderCodecFactory(IServiceProvider serviceProvider)
        {
            this.serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));

            // Get the registered service collection, which can be used to get a list of registered types
            var serviceCollection = serviceProvider.GetService <IServiceCollection>();

            // Retrieve a list of registered types that subclass Codec. Codecs must be registered by
            // their concrete type so we can differentiate between them later when calling GetService().
            this.codecTypes = serviceCollection
                              .Where(t => typeof(Codec).IsAssignableFrom(t.ServiceType))
                              .ToDictionary(
                t => NamedServiceFactory <Codec> .GetServiceName(t.ImplementationType),
                t => t.ImplementationType
                );
        }
示例#2
0
 /// <summary>
 /// Creates a new codec.
 /// <para/>
 /// The <see cref="Codec.Name"/> will be written into the index segment: in order for
 /// the segment to be read this class should be registered by subclassing <see cref="DefaultCodecFactory"/> and
 /// calling <see cref="DefaultCodecFactory.ScanForCodecs(System.Reflection.Assembly)"/> in the class constructor.
 /// The new <see cref="ICodecFactory"/> can be registered by calling <see cref="SetCodecFactory"/> at application startup.</summary>
 protected Codec()
 {
     name = NamedServiceFactory <Codec> .GetServiceName(this.GetType());
 }
示例#3
0
 /// <summary>
 /// Creates a new docvalues format.
 /// <para/>
 /// The provided name will be written into the index segment in some configurations
 /// (such as when using <see cref="Codecs.PerField.PerFieldDocValuesFormat"/>): in such configurations,
 /// for the segment to be read this class should be registered by subclassing <see cref="DefaultDocValuesFormatFactory"/> and
 /// calling <see cref="DefaultDocValuesFormatFactory.ScanForDocValuesFormats(System.Reflection.Assembly)"/> in the class constructor.
 /// The new <see cref="IDocValuesFormatFactory"/> can be registered by calling <see cref="SetDocValuesFormatFactory(IDocValuesFormatFactory)"/>
 /// at application startup.
 /// </summary>
 protected DocValuesFormat()
 {
     this.name = NamedServiceFactory <DocValuesFormat> .GetServiceName(this.GetType());
 }
示例#4
0
 /// <summary>
 /// Creates a new postings format.
 /// <para/>
 /// The provided name will be written into the index segment in some configurations
 /// (such as when using <see cref="PerField.PerFieldPostingsFormat"/>): in such configurations,
 /// for the segment to be read this class should be registered by subclassing <see cref="DefaultPostingsFormatFactory"/> and
 /// calling <see cref="DefaultPostingsFormatFactory.ScanForPostingsFormats(System.Reflection.Assembly)"/> in the class constructor.
 /// The new <see cref="IPostingsFormatFactory"/> can be registered by calling <see cref="SetPostingsFormatFactory(IPostingsFormatFactory)"/> at application startup.</summary>
 protected PostingsFormat()
 {
     this.name = NamedServiceFactory <PostingsFormat> .GetServiceName(this.GetType());
 }