Hi, we created a "default" repository class that should be used by all our modules. But we have no idea how to configure it to be useable by other module dbcontext. our idea was to have a base dbcontext (IBaseDbContext) that can be used instead of the IEfCoreDbContext.
so we tried:
- IDbContext interface inherit from IBaseDbContext instead of IEfCoreDbContext
- DbContext implement IBaseDbContext additionally
- replace IBaseDbContext with new DbContext ( tried attribute, module option and both together )
- manual SetDefaultRepositoryClasses on DbContext
without manual SetDefaultRepositoryClasses ( on each DbContext ) you get the default EfCoreRepository ( instead of the new "default" repository ) without ReplaceDbContext you InvalidOperationException because the Type is not included in the context
- ABP Framework version: v5.3.0
- DB provider: EF Core
In our prototype project we used only one dbcontext for all module, so SetDefaultRepositoryClasses has done the job. But now we are struggling to split it into seperated dbcontext for each module. What would be the best approach for this ?
Thanks
5 Answer(s)
-
0
hi
You can create separate DbContext and Repository in your modules. Please check out our open source modules or the default module template.
https://github.com/abpframework/abp/tree/dev/modules https://docs.abp.io/en/abp/latest/Entity-Framework-Core
-
0
Well we would like to know, how to use one repository for multiple dbcontext - none of your modules share the repository.
-
0
If multiple
dbcontext
have the same entity, they can be used independently, but not together. -
0
so we need to make the base repository generic and create a version for each module. It would be great to be able to override the generic EfCoreRepository independently from the dbcontext
-
0
EfCoreRepository and dbcontext are independent.
so we need to make the base repository generic and create a version for each module
You can give it a try