question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Circular Dependency Exception When using Custom Repository Base

See original GitHub issue

Hey Everyone, I am facing a circular dependency issue while trying to implement a custom repository base class. Here is my code for the base repository.

public class SigmaCHMRepositoryBase<TEntity, TPrimaryKey> : EfCoreRepositoryBase<SigmaCHMDbContext, TEntity, TPrimaryKey>
        where TEntity : class, IEntity<TPrimaryKey>
{
IDbContextProvider<SigmaCHMDbContext> _dbContextProvider;
private ISigmaSession AbpSession;
        public SigmaCHMRepositoryBase(IDbContextProvider<SigmaCHMDbContext> dbContextProvider, ISigmaSession abpSession)
            : base(dbContextProvider)
        {
            _dbContextProvider = dbContextProvider;
            AbpSession = abpSession;
        }
}

*ISigmaSession in inherited from IAbpSession

[AutoRepositoryTypes(
        typeof(IRepository<>),
        typeof(IRepository<,>),
        typeof(SigmaCHMRepositoryBase<>),
        typeof(SigmaCHMRepositoryBase<,>)
        )]
	public class SigmaCHMDbContext : AbpZeroDbContext<Tenant, Role, User, SigmaCHMDbContext>
    {
/* Define a DbSet for each entity of the application */
	}

Everything works fine if I only Inject the DBContext in Repo, but if I inject my ISigmaSession or IUnitofWork it gives circular dependency exception for that.

DEBUG 2019-10-23 18:24:41,866 [1 ] ameworkCore.AbpEntityFrameworkCoreModule - Registering DbContext: SigmaCHM.EntityFrameworkCore.SigmaCHMDbContext, SigmaCHM.EntityFrameworkCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null FATAL 2019-10-23 18:24:42,342 [1 ] Abp.AbpBootstrapper - Castle.MicroKernel.CircularDependencyException: Dependency cycle has been detected when trying to resolve component 'SigmaCHM.Session.SigmaSession'. The resolution tree that resulted in the cycle is the following:

Component 'SigmaCHM.Session.SigmaSession' resolved as dependency of component '41f2dc2176684b5589953b28e9f835c7' resolved as dependency of component 'Abp.MultiTenancy.TenantCache2[[SigmaCHM.MultiTenancy.Tenant, SigmaCHM.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[SigmaCHM.Authorization.Users.User, SigmaCHM.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' resolved as dependency of component 'Abp.MultiTenancy.TenantStore' resolved as dependency of component 'Abp.MultiTenancy.TenantResolver' resolved as dependency of component 'SigmaCHM.Session.SigmaSession' resolved as dependency of component '0e36d4aa8d3f49b7a891874e29fd817e' resolved as dependency of component 'Abp.Localization.ApplicationLanguageManager' resolved as dependency of component 'Abp.Localization.ApplicationLanguageProvider' resolved as dependency of component 'Abp.Localization.LanguageManager' resolved as dependency of component 'Abp.Localization.LocalizationManager' which is the root component being resolved. at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired) at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernelByType(CreationContext context, ComponentModel model, DependencyModel dependency) at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model,

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ismcagdascommented, Oct 25, 2019

@mkamranaslam I don’t know your case very well but RepositoryBase shouldn’t contain much logic. You can instead use Domain Services for that.

0reactions
mkamranaslamcommented, Oct 24, 2019

Then how is it possible to inject/ use IAbpSession in repository base so I can override some functionality or implement some logic on base of IAbpSession.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can not @autowired repository. Bean circular reference
A circular reference is when you have two beans, each injected into the other. ... Since Spring can't inject something that is not...
Read more >
Circular Dependencies in Spring
A quick writeup on dealing with circular dependencies in Spring: how they occur and several ways to work around them.
Read more >
Circular Dependency in Spring Boot: How to Detect and Fix It
Circular dependency can be a common issue when building complex applications using Spring Boot. It occurs when two or more components depend on...
Read more >
Circular Dependencies in Spring
When Spring encountered this type of issue, it raise an exception BeanCurrentlyInCreationException while loading context. Note: We have to ...
Read more >
How to resolve circular dependencies in Spring?
Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'car': Requested bean is currently in creation: Is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found