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

bi-directional dependency while EntityFrameworkCore and AutoMapper are installed #254

Open
OmerNassie opened this issue May 13, 2020 · 2 comments
Labels
question Further information is requested

Comments

@OmerNassie
Copy link

I struggle understand the reason throwing this exception in my project. I searched all over the internet what can cause it while EntityFrameworkCore and AutoMapper are installed and using the AssembliesFromApplicationBaseDirectory() method when scanning for registries.

The full exception message:
Detected some kind of bi-directional dependency while trying to discover and plan a missing service registration. Examining types: AutoMapper.TypePair, Microsoft.EntityFrameworkCore.Metadata.Internal.EntityType

The project's dependencies:

    <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
    <PackageReference Include="Lamar.Microsoft.DependencyInjection" Version="4.3.0" />
    <PackageReference Include="Microsoft.Extensions.DependencyModel" Version="3.1.3" />
    <PackageReference Include="AspNetCore.HealthChecks.UI" Version="3.1.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="4.1.1" />
    <PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="3.1.3" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="5.3.3" />

my configure container method:

        public override void ConfigureContainer(ServiceRegistry registry)
        {
            registry.For<IConfiguration>().Use(Configuration).Singleton();
            registry.Scan(
                c =>
                {
                    c.WithDefaultConventions();
                    c.AssembliesFromApplicationBaseDirectory();
                    c.LookForRegistries();
                });
        }

.Net Core 3.1

@OmerNassie OmerNassie changed the title bi-directional dependency while EntityFrameworkCode and AutoMapper are installed bi-directional dependency while EntityFrameworkCore and AutoMapper are installed May 13, 2020
@jeremydmiller
Copy link
Member

That's not the full stack trace. Lamar tries to give you the whole path of how you made the circle.

And I very strongly recommend against this usage here:

        public override void ConfigureContainer(ServiceRegistry registry)
        {
            registry.For<IConfiguration>().Use(Configuration).Singleton();
            registry.Scan(
                c =>
                {
                    c.WithDefaultConventions();
                    c.AssembliesFromApplicationBaseDirectory();
                    c.LookForRegistries();
                });
        }


That's going to give you oodles of registrations you don't need. Use some kind of allow list to limit the assemblies you're scanning, and that might very well make this problem go away

@jeremydmiller jeremydmiller added the question Further information is requested label Jul 18, 2020
@OmerNassie
Copy link
Author

I managed to do a workaround for this because nothing I tried helped

            registry.For(typeof(Microsoft.EntityFrameworkCore.Metadata.Internal.EntityType)).Use(typeof(Microsoft.EntityFrameworkCore.Metadata.Internal.EntityType));
            registry.For<System.Security.Cryptography.X509Certificates.X509Certificate2>().Use<System.Security.Cryptography.X509Certificates.X509Certificate2>();
            registry.For<System.Security.Cryptography.X509Certificates.X509Certificate>().Use<System.Security.Cryptography.X509Certificates.X509Certificate>();

While investigating the subject, I've already done a whitelist as for your recommendation.
Thank you

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

No branches or pull requests

2 participants