/// <summary>
        /// Method to deal with adding a second core into Microsoft's dependency injection system.
        /// </summary>
        /// <param name="services">The dependency injection service.</param>
        /// <param name="url">The url for the second core.</param>
        /// <param name="setupAction">Allow for custom headers to be injected.</param>
        /// <typeparam name="TModel">The type of model that should be used for this core.</typeparam>
        /// <returns>The dependency injection service.</returns>
        public static IServiceCollection AddSolrNet <TModel>(this IServiceCollection services, string url, Action <SolrNetOptions> setupAction)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (AddedDI <TModel>(services))
            {
                throw new InvalidOperationException($"SolrNet was already addd for model of type {typeof(TModel).Name}");
            }

            services = BuildSolrNet(services, url, setupAction);
            //Set custom http client setting given by user at intiliation for specific solr core
            var autoSolrConnection = new AutoSolrConnection(url);

            if (setupAction != null)
            {
                var solrOption = new SolrNetOptions(autoSolrConnection.HttpClient);
                setupAction(solrOption);
            }
            var connection = new BasicInjectionConnection <TModel>(autoSolrConnection);

            services.AddTransient(typeof(ISolrInjectedConnection <TModel>), (service) => connection);
            return(services);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method to deal with adding a second core into Microsoft's dependency injection system.
        /// </summary>
        /// <param name="services">The dependency injection service.</param>
        /// <param name="url">The url for the second core.</param>
        /// <param name="setupAction">Allow for custom headers to be injected.</param>
        /// <typeparam name="TModel">The type of model that should be used for this core.</typeparam>
        /// <returns>The dependency injection service.</returns>
        public static IServiceCollection AddSolrNet <TModel>(this IServiceCollection services, string url, Action <SolrNetOptions> setupAction)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (AddedDI <TModel>(services))
            {
                throw new InvalidOperationException($"SolrNet was already addd for model of type {typeof(TModel).Name}");
            }

            services = BuildSolrNet(services, url, setupAction);
            var connection = new BasicInjectionConnection <TModel>(new AutoSolrConnection(url));

            services.AddTransient(typeof(ISolrInjectedConnection <TModel>), (service) => connection);
            return(services);
        }