jspuij / RESTier

A turn-key library for building RESTful services
http://odata.github.io/RESTier
Other
2 stars 0 forks source link

InvocationContext derivatives hold a reference to a non scoped IServiceProvider. #14

Closed jspuij closed 5 years ago

jspuij commented 5 years ago

The idea of the developers was that InvocationContext derivatives would provide a reference to a scoped IServiceProvider.

unfortunately ApiBase is singleton and InvocationContext derivates are (and were) instantiated with Api.ServiceProvider as reference. This means that they receive a non scoped container and All AddScoped<> services will effectively return a singleton.

SubIssue of https://github.com/jspuij/RESTier/issues/13.

jspuij commented 5 years ago

Example here:

https://github.com/OData/RESTier/blob/master/src/Microsoft.Restier.Core/Extensions/ApiBaseExtensions.cs#L397

jspuij commented 5 years ago

services.AddScoped<RestierQueryExecutorOptions>() is an example where it goes horribly wrong. A single RestierQueryExecutorOptions instance is used, which makes multiple concurrent queries with and without TotalCount possibly get the wrong results or no count where one was requested or vice versa.

jspuij commented 5 years ago

Part of https://github.com/OData/RESTier/issues/629

jspuij commented 5 years ago

It seems I was wrong. ApiBase is scoped, although the documentation suggests it's not. The documentation talks about the Configuration being singleton, and I incorrectly assumed that ApiBase would be singleton in Total.