c# - How does the "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" package resolves types which are in &

admin2025-04-16  6

I have a class library project which has the following extension method -

public static async Task DoSomethingAsync(this WebApplication app)
{
    //
}

I was curious how a class library project is resolving the WebApplication type, which I knew resided in the Microsoft.AspNetCore.dll. I failed to find any clue. What I found though is the project has the Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore NuGet package installed, and if I remove this package, it can no longer resolve the WebApplication type.

I checked the transitive dependencies of this package on NuGet Package Manager and didn't find anything that could give me a hint how it could resolve a type in Microsoft.AspNetCore.dll -

Apparently this Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore package is also resolving the IAuthorizationService type for me which resides in Microsoft.AspNetCore.Authorization.dll, and I couldn't figure out how.

Can anyone help me get my head around how the package referencing or type resolving happening here?

I have a class library project which has the following extension method -

public static async Task DoSomethingAsync(this WebApplication app)
{
    //
}

I was curious how a class library project is resolving the WebApplication type, which I knew resided in the Microsoft.AspNetCore.dll. I failed to find any clue. What I found though is the project has the Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore NuGet package installed, and if I remove this package, it can no longer resolve the WebApplication type.

I checked the transitive dependencies of this package on NuGet Package Manager and didn't find anything that could give me a hint how it could resolve a type in Microsoft.AspNetCore.dll -

Apparently this Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore package is also resolving the IAuthorizationService type for me which resides in Microsoft.AspNetCore.Authorization.dll, and I couldn't figure out how.

Can anyone help me get my head around how the package referencing or type resolving happening here?

Share edited Feb 2 at 20:35 Guru Stron 144k11 gold badges172 silver badges212 bronze badges asked Feb 1 at 22:33 atiyaratiyar 8,3277 gold badges40 silver badges82 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Adding Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore results in the ASP.NET Core brought as a dependency to your project. If you check the .csproj file for it @github you will see that it references several projects which are not mentioned in the dependencies of the nuget:

<ItemGroup>
    <Reference Include="Microsoft.AspNetCore.Diagnostics.Abstractions" />
    <Reference Include="Microsoft.AspNetCore.Http.Abstractions" />
    <Reference Include="Microsoft.AspNetCore.Http.Extensions" />
    <!--  ...  -->
</ItemGroup>

All of them have IsAspNetCoreApp property set to True (and IsPackable to false) in their .csproj files which means that all of them are parts of the shared ASP.NET Core framework (link 1, link 2) which is not distributed as packages. Not sure how it works exactly but that's it basically.

Also note that usually you will bring the ASP.NET Core shared framework to a class library via FrameworkReference.

转载请注明原文地址:http://www.anycun.com/QandA/1744814389a87988.html