/// <summary> /// Add SolrExpress framework services in DI container /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="builder">Options builder action</param> /// <returns>Configured DocumentCollectionOptionsBuilder</returns> public static DocumentCollectionBuilder <TDocument> AddSolrExpress <TDocument>(this IServiceCollection services, Action <DocumentCollectionBuilder <TDocument> > builder) where TDocument : IDocument { Checker.IsNull(builder); var builderObj = new DocumentCollectionBuilder <TDocument>(); builderObj.Engine = new NetCoreEngine(services); builder.Invoke(builderObj); var documentCollection = builderObj.Create(); var expressionCache = new ExpressionCache <TDocument>(); var expressionBuilder = new ExpressionBuilder <TDocument>(expressionCache); documentCollection .Engine .AddSingleton <DocumentCollectionOptions <TDocument>, DocumentCollectionOptions <TDocument> >(builderObj.Options) .AddSingleton <ISearchParameterBuilder <TDocument>, SearchParameterBuilder <TDocument> >() .AddSingleton <IExpressionCache <TDocument>, ExpressionCache <TDocument> >(expressionCache) .AddSingleton <IExpressionBuilder <TDocument>, ExpressionBuilder <TDocument> >(expressionBuilder) .AddSingleton <IEngine, NetCoreEngine>((NetCoreEngine)builderObj.Engine) .AddSingleton <ISearchParameterBuilder <TDocument>, SearchParameterBuilder <TDocument> >() .AddTransient <IDocumentCollection <TDocument>, DocumentCollection <TDocument> >(documentCollection) .AddTransient <ISolrSearch <TDocument>, SolrSearch <TDocument> >() .AddTransient <ISolrAtomicUpdate <TDocument>, SolrAtomicUpdate <TDocument> >(); ExpressionCacheWarmup.Load(expressionBuilder); return(builderObj); }
public void ExpressionCacheWarmup001() { // Arrange PropertyInfo propertyInfo; SolrFieldAttribute solrFieldAttribute; var expressionCache = (IExpressionCache <TestDocument>) new ExpressionCache <TestDocument>(); var expressionBuilder = new ExpressionBuilder <TestDocument>(expressionCache); Expression <Func <TestDocument, object> > expression1 = (q) => q.Id; Expression <Func <TestDocument, object> > expression2 = (q) => q.Score; Expression <Func <TestDocument, object> > expression3 = (q) => q.Spatial; Expression <Func <TestDocument, object> > expression4 = (q) => q.Dummy; bool result1; bool result2; bool result3; bool result4; // Act ExpressionCacheWarmup.Load(expressionBuilder); // Assert result1 = expressionCache.Get(expression1, out propertyInfo, out solrFieldAttribute); result2 = expressionCache.Get(expression3, out propertyInfo, out solrFieldAttribute); result3 = expressionCache.Get(expression4, out propertyInfo, out solrFieldAttribute); result4 = expressionCache.Get(expression4, out propertyInfo, out solrFieldAttribute); Assert.True(result1); Assert.True(result2); Assert.True(result3); Assert.True(result4); }