Open Closed

How to add Dapper to existing porject #2745


User avatar
0
oshabani created

we were adding Dapper to our project using this article https://docs.abp.io/en/abp/latest/Dapper

but we face the issue of DependencyResolutionException None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Sbg.ProjectControl.Locations.LocationsAppService' can be invoked with the available services and parameters: Cannot resolve parameter 0

ABP Framework version: v5.1

  • UI type: MVC

  • DB provider: EF Core

  • Tiered (MVC) or Identity Server Separated (Angular): yes

  • Exception message and stack trace:DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Sbg.ProjectControl.Locations.LocationsAppService' can be invoked with the available services and parameters: Cannot resolve parameter 'Sbg.ProjectControl.Locations.ILocationDapperRepository locationDapperRepository' of constructor 'Void .ctor(Sbg.ProjectControl.Locations.ILocationRepository, Volo.Abp.Domain.Repositories.IRepository`2[Sbg.ProjectControl.SubProjects.SubProject,System.Int32], Sbg.ProjectControl.Locations.ILocationDapperRepository)'.

  • Steps to reproduce the issue:

    • Add Volo.Abp.Dapper package to the EntityFramewokCore solution
    • Create a Module class for Dapper :
      • namespace Sbg.ProjectControl.EntityFrameworkCore { [DependsOn(typeof(AbpDapperModule))] public class ProjectControlDapperModule:AbpModule { }
    • create a Dapper repository interface public interface ILocationDapperRepository:IRepository<Location,int>
    • create Dapper repository implement the interface public class DapperLocationRepository : DapperRepository<ProjectControlDbContext>, ITransientDependency, ILocationDapperRepository
    • in the Application service private readonly ILocationDapperRepository _locationDapperRepository;
    • in the constructor i added a parameter to inject the repository
      • public LocationsAppService(ILocationRepository locationRepository, IRepository<SubProject, int> subProjectRepository, ILocationDapperRepository locationDapperRepository)

    that is!

  • we need to know how to fix this issue


9 Answer(s)
  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Hi, you don't need to inherit your repository class from the IRepository<TEntity, TKey> interface. If you remove it, you don't get the DependencyResolutionException.

  • User Avatar
    0
    oshabani created

    Hi dose not work this is my ILocationDapperRepository and this is my Application service injection constructor this is my Dapper Repository

    this is my Dapper Module which i didnt use it in any where but i still have the error


  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Did you add DependsOn[typeof(ProjectControlDapperModule)] to your web module class as below:

    //other depends on statements...
    [DependsOn(typeof(ProjectControlDapperModule))]
    public class MyWebModule : AbpModule 
    {
        //...
    }
    
  • User Avatar
    0
    oshabani created

    I already added but it is not working

  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Can you send your application to engin.veske@volosoft.com?

  • User Avatar
    0
    oshabani created

    sure , i sent it to your email as Dropbox link

  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Thanks @oshabani, I'll examine it and inform you asap.

  • User Avatar
    0
    oshabani created

    thanks waiting for your feedback

  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    I've shared the solution with you via mail and it should fix your problem. So, I close the question, if you encounter a problem please feel free to re-open the question.

    Best regards.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11