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

Self referencing loop detected #81

Closed
csimonsson opened this issue Aug 16, 2024 · 3 comments · Fixed by #83
Closed

Self referencing loop detected #81

csimonsson opened this issue Aug 16, 2024 · 3 comments · Fixed by #83

Comments

@csimonsson
Copy link

Hi,

I'm having issues when using minimal API and dependency injection for my DbContext, where my DbContext is serialized with an exception:

Self referencing loop detected
at IdempotentAPI.Core.Idempotency.PrepareMinimalApiIdempotencyAsync

How do I avoid that some of my arguments (DI) to the API functions are treated as arguments when they should not be included in the hash?

Example:

    private static async Task<Results<Created<CustomerDTO>> CreateCustomer(
        [FromServices] DbContext context,
        [FromBody] CreateCustomerRequest request
        )
    {
        ...
    }

The issue seems to be similar to #67

@ikyriak
Copy link
Owner

ikyriak commented Aug 18, 2024

Hello @csimonsson,

Thank you for reporting this issue. I have prepared a backward-compatible solution to define the special types to be excluded from serialization in the IIdempotencyOptionsProvider. For example:

NuGet Packages:

Program.cs

// ...
builder.Services.AddIdempotentMinimalAPI(new IdempotencyOptionsProvider());
// ...

IdempotencyOptionsProvider.cs

using IdempotentAPI.Core;
using IdempotentAPI.MinimalAPI;
using IdempotentAPI.TestWebMinimalAPIs.ApiContext;
using Microsoft.EntityFrameworkCore;

namespace IdempotentAPI.TestWebMinimalAPIs
{
    public class IdempotencyOptionsProvider : IIdempotencyOptionsProvider
    {
        private readonly List<Type> ExcludeRequestSpecialTypes = new()
        {
            typeof(DbContext),
            typeof(ApiDbContext),
        };

        public IIdempotencyOptions GetIdempotencyOptions(IHttpContextAccessor httpContextAccessor)
        {
            // WARNING: This example implementation shows we can provide different IdempotencyOptions per case.
            //switch (httpContextAccessor?.HttpContext?.Request.Path)
            //{
            //    case "/v6/TestingIdempotentAPI/test":
            //        return new IdempotencyOptions()
            //        {
            //            ExpireHours = 1,
            //            ExcludeRequestSpecialTypes = ExcludeRequestSpecialTypes,
            //        };
            //}

            return new IdempotencyOptions()
            {
                ExcludeRequestSpecialTypes = ExcludeRequestSpecialTypes,
            };
        }
    }
}

@csimonsson
Copy link
Author

Thanks, I will try it out!

@csimonsson
Copy link
Author

Got it working with some minor changes #82 , thanks again!

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

Successfully merging a pull request may close this issue.

2 participants