Base solution for your next web application
Open Closed

Create Controllers For App Services Setup Issue #2376


User avatar
0
rev319303 created

What am I missing?

I am trying to setup the create controllers for app services and it is not working.

Here is what I placed in my PreInitialize method in my web.mvc project. (Core/jquery project)

Configuration.Modules.AbpAspNetCore().CreateControllersForAppServices(typeof(DiversionCore.DiversionCoreApplicationModule).Assembly, moduleName: "app", useConventionalHttpVerbs: true);

Here is the setup of my customerAppService:

namespace DiversionCore.Customer
{
    public class CustomerAppService : DiversionCoreAppServiceBase, ICustomerAppService
    {
        private readonly IRepository<Customer> _customerRepository;
        private readonly IRepository<CustomerSubscription> _customerSubscriptionRepository;
        private readonly IStripeAppService _stripeAppService;
        private readonly IUnitOfWorkManager _unitOfWorkManager;

        public CustomerAppService(IRepository<Customer> customerRepository, 
            IRepository<CustomerSubscription> customerSubscriptionRepository, 
            IStripeAppService stripeAppService,
            IUnitOfWorkManager unitOfWorkManager)
        {
            _customerRepository = customerRepository;
            _customerSubscriptionRepository = customerSubscriptionRepository;
            _stripeAppService = stripeAppService;
            //_unitOfWorkManager = unitOfWorkManager;
        }

        public async Task<CustomerDto> GetCustomer()
        {
            CustomerDto model = new CustomerDto();
            if (AbpSession.UserId.HasValue)
            {
                var qry = await _customerRepository.FirstOrDefaultAsync(x => x.UserId == AbpSession.UserId.Value);
                
                if(qry != null)
                {
                    model = Mapper.Map<Customer, CustomerDto>(qry);
                    model.CurrentSubscriptionId = qry.CustomerSubscriptionList.Where(x => x.IsActive == true).Select(x => x.SubscriptionId).FirstOrDefault();
                    return model;
                }
            }
            return null;
        }
    }
}

Here is what I am typing in the browser which returns undefined:

var _customerService = abp.services.app.Customer;

4 Answer(s)
  • User Avatar
    0
    rev319303 created

    I figured it out. It is case sensitive and wants camel case on the call. I changed my ajax call to this:

    var _customerService = abp.services.app.customer;
    _customerService.createNewStripeCustomerWithSubscription({
                        CaseType: "Unlimited",
                        stripeToken: token.id,
                        StripeEmail: token.email
                    }).done(function () {
                        abp.notify.success("Successfully created subscription. Thank-You for your purchase!");
                    });
    

    Also, this was not needed in the PreInitialize()

    Configuration.Modules.AbpAspNetCore().CreateControllersForAppServices(typeof(DiversionCore.DiversionCoreApplicationModule).Assembly, moduleName: "app", useConventionalHttpVerbs: true);
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Thanks for sharing your solution :).

  • User Avatar
    0
    exlnt created

    I'm having the exact same issue. I copied one of my working Index.js files and simply updated the name to the new service and changed the code as needed for the new entity. Yet I keep getting "undefined" app service. Please help!

    [https://drive.google.com/file/d/0B5HAoiVVXzY7UTRDQlNLNHpjaW8/view?usp=sharing])

    Update: I solvedmy issue. :D I looked at the log files and found that the dynamic web api had named my service "companyAddress". It was another camel case issue.

  • User Avatar
    0
    ismcagdas created
    Support Team

    :)