Closed danilobreda closed 1 year ago
What im doing...
@mookid8000 is that possible?
I created a example on a fork https://github.com/danilobreda/Rebus.ServiceProvider Project Sample.WebAppPipes
Workflow of the example: Api Call (Controller) -> Publish MessageA -> Handler of MessageA -> Publish MessageB -> Handler of Message B SessionData GUID originated from Controller should be the same to the Handler of Message B... that not occurs
I created a temporary solution with a custom IMessenger(Injecting IBus) that publish/send/sendlocal with headers from my scoped ISessionData and this incomingstep
public async Task Process(IncomingStepContext context, Func<Task> next)
{
var message = context.Load<Message>();
var serviceProvider = context.Load<IServiceProvider>();
using (var scope = serviceProvider.CreateScope())
{
//setting sessiondata into IsessionData
var sess = scope.ServiceProvider.GetRequiredService<ISessionData>();
sess.SetSessionGuid(message.GetSessionGuid());
sess.SetSessionInfo(message.GetSessionInfo());
sess.SetApiInfo(message.GetApiInfo());
context.Save(scope);
await next();
}
}
Your issue is quite natural, because it's the root service provider that gets injected here:
public class CustomFlowOutgoingStep : IOutgoingStep
{
private IServiceProvider _serviceProvider;
// 👇 root
public CustomFlowOutgoingStep(IServiceProvider provider)
{
_serviceProvider = provider;
}
(...)
The newest Rebus.ServiceProvider (9.0.0-b02) has had some work done to make it easier to get access the current IServiceScope
(or AsyncServiceScope
if you're on .NET 6 or later) – check out an example here: https://github.com/rebus-org/Rebus.ServiceProvider/blob/master/Rebus.ServiceProvider.Tests/Examples/DigOutServiceProviderScopeInOutgoingStep.cs
I'm taking the liberty of closing this issue for now. Let me know if you still have questions about this 🙂
The project is a API AspNetCore running on .net 7 (with latest nugets) using Microsoft DI. I have a scoped interface name ISessionData that have the informations of the http request received by a asp net core api controller. When i receive the HTTP request, i set the informations to the ISessionData (scoped) by a http middleware/filter
If this controller call a publish for example, the CustomFlowOutgoingStep receive ISessionData with different info (like a new one was created). The ideia is set informations of the sessiondata on the Event (headers)
var sessionData null above...
what im doing wrong? :(