JobScheduler HttpClient.SendAsync disposes my IServiceProvider #1087
Replies: 4 comments
-
in general the principle is after u await u should query the db again meaning create a new objectSpace and do objectSpace.GetObject(objectB4TheAwait) |
Beta Was this translation helpful? Give feedback.
-
sounds very complicated, do you have a reference so that I can read more about it? I will test it with my injected INonSecuredObjectSpaceFactory. I am using one ObjectSpace with multiple NestedObjectSpaces to just commit one time to db. If I would create a new objectSpace everytime, I would lose this easy OS/Nested-connection. |
Beta Was this translation helpful? Give feedback.
-
public static async Task DailyOrders() {
await Provider.RunWithStorageAsync(application => application.CreateOrders()
.SelectMany(orders=>HttpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, $"/api/orders?lenght?{orders.Length}")).ToObservable()
.SelectMany(message => application.UseArray(orders,orders1 => orders1.Do(order => order.UpdateTime=DateTime.Now).Commit()))))
.ToObservable().To(true);
} not that complex this framework has all the extensions u need at the right place. Note that this case is about .NET not about XAF or eXpand |
Beta Was this translation helpful? Give feedback.
-
My main goal was to check if my injected OS would work. I've never read that you need to create a new OS after awaiting httpclient. Thats what I was asking for. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
first I want to mention that this might or might be not related to eXpand.
I was struggling long to find the cause of my issue and want to ask if it is correct to do it the way I do.
I've set up a XAF Blazor App with eXpand JobScheduler.
As the docs state we have to create a new job for example like follows:
Everything worked fine until I switched my API-calls from
HttpClient.SendAsync().Result
toawait HttpClient.SendAsync()
awaiting SendAsync disposes my IServiceProvider, therefore I cant use my ObjectSpace anymore.
The solution for me is to use .Result instead of await (poor implementation) or just Inject for example INonSecuredObjectSpaceFactory instead of IServiceProvider.
So as I don't understand what your code does (it looks like magic every time for me) for example "RunWithStorageAsync" and so on, I just want to show you my current implementation and ask if it is correct this way?
For me it is working but there is surely any reason why you did it as you did with ServiceProvider and so on.
Beta Was this translation helpful? Give feedback.
All reactions