Circular Dependency Exception When using Custom Repository Base
See original GitHub issueHey 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:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
@mkamranaslam I don’t know your case very well but RepositoryBase shouldn’t contain much logic. You can instead use Domain Services for that.
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.