Initially I had a LINQ query (say EF or any other) with expected deffered execution:
class Provider : IProvider
{
public IEnumerable<Any> GetSome()
{
yield return new Any(); // LINQ query
}
}
But now such a provider moved into a WCF service (and IoC):
unityContainer.RegisterType<IProvider>(
new PerResolveLifetimeManager(),
new InjectionFactory(c => new ChannelFactory<T>("IService").CreateChannel()));
Is it possible to preserve deferred execution over WCF call?
This is answer is actually an answer to your last comment to Ladislav Mrnka. You say:
While it doesn’t come for free, it is still possible!
On the server side, you would have to provide a method to initialize the request and a method to get the results, one by one.
On the client side – specifically on one of its low level infrastructure classes – you can wrap it in an enumerator and finally, your “business” classes can use that enumerator just like any other.
We already discussed that it will introduce additional overhead in the means of the request-response needed for each item. This will introduce latency and increase the network load.
A sample of this approach using a pseudo RESTful API could look like this:
Server side:
POST http://server/api/search-specification:The body contains the parameters needed for your search, e.g. start date and end date
The response will be an URI identifying the search-specification.
GET http://server/api/search-specification/1/next-result:The response will be the next item.
The controller for this looks something like this:
I am calling it a pseudo RESTful API, because it certainly looks like one, but it needs to internally keep state for each specification to enable the deferred execution. Additionally
GET http://server/api/search-specification/1/next-resultis not idempotent.But I think it demonstrates what I mean 🙂
The client side would encapsulate it somehow like this:
And you would use it like this:
Just a raw sketch on how you could implement something like this.