Base solution for your next web application
Open Closed

Respository Injecion Failed #187


User avatar
0
thobiasxp created

Followed the Module Zero Development Step by step guide..I was created the Persons Table using Code first....After Created table the Persons Repository is not injected.....I stuck up in that area...what i have to do for Getting Persons Repository...Make Reply As soon......


10 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Please share you Entity and the code where you're trying to inject repository.

    Problem is probably about your EF configuration.

    • Have you defined a Product entity class derived from Entity (or Entity<T>) ?
    • Did you added a DbSet to your dbcontext for your Product entity?
  • User Avatar
    0
    thobiasxp created

    Here i include the phone book service class ...i followed the step by step development guide....but how after creating the interface and view model how the repository is injected kindly explain it detailed.

    using Abp.Application.Services.Dto; using Abp.Domain.Repositories; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using TIBS.stem.Storage; using TIBS.stem.Tenants.Phonebook.Dto;

    namespace TIBS.stem.Tenants.Phonebook { public class PersonAppService : stemAppServiceBase, IPersonAppService { private readonly IRepository<Person> _personRepository;

        public PersonAppService(IRepository&lt;Person&gt; personRepository)
        {
            _personRepository = personRepository;
        }
    
        public ListResultOutput&lt;PersonListDto&gt; GetPeople(GetPeopleInput input)
        {
            var persons = _personRepository
                .GetAll()
                .WhereIf(
                    !input.Filter.IsNullOrEmpty(),
                    p => p.Name.Contains(input.Filter) ||
                            p.Surname.Contains(input.Filter) ||
                            p.EmailAddress.Contains(input.Filter)
                )
                .OrderBy(p => p.Name)
                .ThenBy(p => p.Surname)
                .ToList();
    
            return new ListResultOutput&lt;PersonListDto&gt;(persons.MapTo&lt;List&lt;PersonListDto&gt;>());
        }
    }
    

    }

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    ASP.NET Boilerplate automatically registers and injects IRepository<T> (IRepository<Person> in this case). Your application service seems correct. If you defined Person and added to DbContext (as like here <a class="postlink" href="http://www.aspnetzero.com/Documents/Developing-Step-By-Step#creating-person-entity">http://www.aspnetzero.com/Documents/Dev ... son-entity</a>) then it should be worked. Please share the exact error message you received. Also, you can download the working sample project from <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-samples">https://github.com/aspnetzero/aspnet-zero-samples</a> to compare with your codes.

  • User Avatar
    0
    thobiasxp created

    Hi,

    Thank you for your Valuable Reply....I will Check it and Inform...Thanks a lot

  • User Avatar
    0
    thobiasxp created

    Hi

    Actually I am getting an error in the following Bold area.I got an error in person app service GETPEOPLE method... WHERE AND FILTER condition....

    in that area i got an following error

    'System.Linq.IQueryable<TIBS.stem.Storage.Person>' does not contain a definition for 'WhereIf' and no extension method 'WhereIf' accepting a first argument of type 'System.Linq.IQueryable<TIBS.stem.Storage.Person>' could be found (are you missing a using directive or an assembly reference?)

    but i properly created the entity class also mentioned the class in dbcontext....

    also added the person app service code for your reference......

    using Abp.Application.Services.Dto; using Abp.Domain.Repositories; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using TIBS.stem.Storage; using TIBS.stem.Tenants.Phonebook.Dto;

    namespace TIBS.stem.Tenants.Phonebook { public class PersonAppService : stemAppServiceBase, IPersonAppService { private readonly IRepository<Person> _personRepository;

    public PersonAppService(IRepository<Person> personRepository) { _personRepository = personRepository; }

    public ListResultOutput<PersonListDto> GetPeople(GetPeopleInput input) { var persons = _personRepository .GetAll() .WhereIf( !input.Filter.IsNullOrEmpty(), p => p.Name.Contains(input.Filter) || p.Surname.Contains(input.Filter) || p.EmailAddress.Contains(input.Filter) ) .OrderBy(p => p.Name) .ThenBy(p => p.Surname) .ToList();

    return new ListResultOutput<PersonListDto>(persons.MapTo<List<PersonListDto>>()); } } }

  • User Avatar
    0
    hikalkan created
    Support Team

    Oopppss.. Then it is simple!

    WhereIf is a special extension method of ABP to simplify writing queries.

    just add namespace "Abp.Linq.Extensions" namespace to your file.

    using Abp.Linq.Extensions
    

    Normally, Visual Studio should find it.

  • User Avatar
    0
    thobiasxp created

    Hi,

    It's Worked. Thanks a lot...I have a doubt how to map the service class in angular js...

    ex: '$scope', 'abp.services.app.person'

    where the abp.services.app.person service class is created.....how to map this to Angular js controller.....explain it detailed

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    There is a documentation: <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Dynamic-Web-API">http://www.aspnetboilerplate.com/Pages/ ... ic-Web-API</a> We use ForAll method with "app" namespace prefix.

  • User Avatar
    0
    ramcharan created

    Hi

    I too have the same problem. But i used Abp.Linq.Extensions and im getting error as There is no argument given that corresponds to the required formal parameter 'value' of 'string.IsNullOrEmpty(string)'

    My code is using Abp.Application.Services; using Abp.Application.Services.Dto; using Abp.AutoMapper; using BCITS.BsmartWater.Storage; using Abp.Domain.Repositories; using Abp.Collections.Extensions; using Abp.Linq.Extensions; using System.Collections.Generic; using System.Linq;

    namespace BCITS.BsmartWater { public interface IPersonAppService : IApplicationService { ListResultOutput<PersonListDto> GetPeople(GetPeopleInput input); } public class GetPeopleInput : IInputDto { public string Filter { get; set; } }

    [AutoMapFrom(typeof(Person))]
    public class PersonListDto : FullAuditedEntityDto
    {
        public string Name { get; set; }
    
        public string Surname { get; set; }
    
        public string EmailAddress { get; set; }
    }
    
    public class PersonAppService : BsmartWaterAppServiceBase, IPersonAppService
    {
        private readonly IRepository&lt;Person&gt; _personRepository;
    
        public PersonAppService(IRepository&lt;Person&gt; personRepository)
        {
            _personRepository = personRepository;
        }
    
        public ListResultOutput&lt;PersonListDto&gt; GetPeople(GetPeopleInput input)
        {
            var persons = _personRepository
                .GetAll()
                .WhereIf(
                    !input.Filter.**IsNullOrEmpty**(),
                    p => p.Name.Contains(input.Filter) ||
                            p.Surname.Contains(input.Filter) ||
                            p.EmailAddress.Contains(input.Filter)
                )
                .OrderBy(p => p.Name)
                .ThenBy(p => p.Surname)
                .ToList();
    
            return new ListResultOutput&lt;PersonListDto&gt;(persons.MapTo&lt;List&lt;PersonListDto&gt;>());
        }
    }
    

    }

    The text i mentioned in bold is getting error. Please help out asap.

  • User Avatar
    0
    hikalkan created
    Support Team

    Just add a "using Abp.Extensions;" into your file. It should be found your IDE normally.