Search code examples
.net-6.0webapiinsight.database

DI broken in .NET6?


I'm doing something completely normal - registering Insight.Database autointerfaces in WebApi DI.

Here's the code -

var dataString = builder.Configuration.GetConnectionString("DefaultConnection");

SqlInsightDbProvider.RegisterProvider();
var connection = new SqlConnection(dataString);
builder.Services.AddTransient(thing => connection.AsParallel<IUserData>());
builder.Services.AddTransient(thing => connection.AsParallel<IRoleData>());

And I'm getting this bizarre error at the point where the injected interfaces are used in a controller.

wierd error message

And there's no documentation on it. Nothing has changed from other projects where it works perfectly fine. It's just... broken.

Any help would be hugely appreciated

Editing to add stack trace

Stack Trace


Solution

  • Inevitably, the problem turned out to be between keyboard and chair.

    I was attempting to structure my returns from the database using Insight's [Recordset] attributes like so...

    [Recordset(1, typeof(UserClaim), GroupBy = nameof(UserClaim.UserId), Into=nameof(ApplicationUser.UserClaims))]
    

    except I'd forgotten to specify the relationship type. So amending this on all applicable calls to

    [Recordset(1, typeof(UserClaim), IsChild = true, GroupBy = nameof(UserClaim.UserId), Into=nameof(ApplicationUser.UserClaims))]
    

    sorted it all out.