Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry and scoped services #8

Open
YeskaNova opened this issue Dec 6, 2019 · 2 comments
Open

Retry and scoped services #8

YeskaNova opened this issue Dec 6, 2019 · 2 comments

Comments

@YeskaNova
Copy link

Hi,

When you retry an inbound request, you reuse the same ServiceScope, I think that it's more natural and expected behavior to create a new Scope for each retry otherwise retries won't be independent to each other ( Imagine a DbContext as a ScopedService, we sure want to have a new DbContext ( Unit of Work ) for each retry ).

Yassine

@YeskaNova
Copy link
Author

YeskaNova commented Dec 6, 2019

A workaround would be :

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        app.UseExceptionHandlingPolicies();
        app.Use(async (context,next)=> {
            try
            {
                await next();
            }
            catch
            {
                context.RequestServices = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope().ServiceProvider;
                throw;
            }
        });

It should be put somewhere like here.

The problem is that the Scope returned by CreateScope() is IDisposable and should be tracked somewhere to be Disposed when the request is finished. Do you have an idea how we can achieve this ?

@IharYakimush
Copy link
Owner

Hi,

Retry feature is obsolete, I would not recommend to retry entire request. Instead use retry in particular place where transient fault can occurs. For instance:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants