Skip to content

Commit a6ea99a

Browse files
author
Ihar Yakimush
committed
solr startup
1 parent 98eaa6f commit a6ea99a

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

SolrNet.IntegrationOData/Controllers/ValuesController.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,30 @@ namespace SolrNet.IntegrationOData.Controllers
1313
[ApiController]
1414
public class ValuesController : ControllerBase
1515
{
16+
public ISolrOperations<Product> Solr { get; }
17+
18+
public ValuesController(ISolrOperations<Product> solr)
19+
{
20+
Solr = solr ?? throw new ArgumentNullException(nameof(solr));
21+
}
1622
// GET api/values
1723
[HttpGet]
1824
public IActionResult Get()
1925
{
2026
return this.Ok(new string[]
2127
{
22-
"http://localhost:64623/api/values/1?$filter=price gt 100&$orderby=Popularity desc&$top=3&$skip=1",
23-
"http://localhost:64623/api/values/1?$filter=Popularity ne null",
24-
"http://localhost:64623/api/values/1?$filter=Popularity eq null",
28+
"http://localhost:61452/api/values/1?$filter=price gt 100&$orderby=Popularity desc&$top=3&$skip=1",
29+
"http://localhost:61452/api/values/1?$filter=Popularity ne null",
30+
"http://localhost:61452/api/values/1?$filter=Popularity eq null",
31+
"http://localhost:61452/api/values/1?$filter=Categories/any(c: c eq 'electronics')",
2532
});
2633
}
2734

2835
// GET api/values/5
2936
[HttpGet("{id}")]
3037
public ActionResult<string> Get(int id, ODataQueryOptions odata)
3138
{
32-
return this.Ok(Product.SolrOperations.Value.AsQuerable().OData().ApplyQueryOptionsWithoutSelectExpand(odata).ToSolrQueryResults());
39+
return this.Ok(this.Solr.AsQuerable().OData().ApplyQueryOptionsWithoutSelectExpand(odata).ToSolrQueryResults());
3340
}
3441

3542
// POST api/values

SolrNet.IntegrationOData/Product.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,5 @@ public class Product
3636

3737
[SolrField("inStock_b")]
3838
public bool InStock { get; set; }
39-
40-
public static Lazy<ISolrOperations<Product>> SolrOperations = new Lazy<ISolrOperations<Product>>(() =>
41-
{
42-
IServiceCollection services = new ServiceCollection();
43-
services.AddSolrNet("http://localhost:8983/solr/demo");
44-
45-
return services.BuildServiceProvider().GetRequiredService<ISolrOperations<Product>>();
46-
}, LazyThreadSafetyMode.ExecutionAndPublication);
4739
}
4840
}

SolrNet.IntegrationOData/Startup.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public Startup(IConfiguration configuration)
2525
public void ConfigureServices(IServiceCollection services)
2626
{
2727
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
28+
services.AddSolrNet("http://localhost:8983/solr/demo");
2829
}
2930

3031
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -35,7 +36,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
3536
app.UseDeveloperExceptionPage();
3637
}
3738

38-
app.UseMvc();
39+
app.UseMvcWithDefaultRoute();
3940
}
4041
}
4142
}

SolrNet.Linq/SolrNet.Linq.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</PropertyGroup>
1616

1717
<ItemGroup>
18-
<PackageReference Include="SolrNet.Core" Version="1.0.10" />
18+
<PackageReference Include="SolrNet.Core" Version="1.0.0" />
1919
</ItemGroup>
2020

2121
</Project>

0 commit comments

Comments
 (0)