Reputation: 213
I downloaded the ASP.NET MVC with AngularJS and Entity Framework, module zero sample. I added an entity called DivePlan, with only one string property name for now.
namespace PlanMyDive.DivePlan
{
public class DivePlan : Entity
{
public virtual string Name { get; set; }
public DivePlan() { }
public DivePlan(string name)
{
this.Name = name;
}
}
}
Then I created a service in the application layer:
namespace PlanMyDive.DivePlan.Dto
{
[AutoMapTo(typeof(DivePlan))]
public class CreateDivePlanInput
{
[Required]
public string Name { get; set; }
}
}
namespace PlanMyDive.DivePlan
{
public class DivePlanAppService : IDivePlanAppService
{
private readonly IRepository<DivePlan> _divePlanRepository;
public DivePlanAppService(IRepository<DivePlan> personRepository)
{
_divePlanRepository = personRepository;
}
public void CreateDivePlan(CreateDivePlanInput input)
{
var diveplan = input.MapTo<DivePlan>();
_divePlanRepository.Insert(diveplan);
}
}
}
namespace PlanMyDive.DivePlan
{
public interface IDivePlanAppService : IApplicationService
{
void CreateDivePlan(CreateDivePlanInput input);
}
}
Finally, I added a page Plans in the Angular routes and implemented as follows:
(function () {
angular.module('app').controller('app.views.plans.plan', [
'$scope', '$modal', 'abp.services.app.divePlan',
function ($scope, $modal, divePlanService) {
var vm = this;
vm.divePlan = {
name: 'MyDivePlan'
};
vm.createNewDivePlan = function () {
abp.ui.setBusy();
divePlanService.createDivePlan(vm.divePlan);
abp.ui.clearBusy();
};
}
]);
})();
@using PlanMyDive.DivePlan
<div ng-controller="app.views.plans.plan as vm">
<h1>Welcome to your DivePlan</h1>
<div class="row">
<div class="col-md-12">
<form name="planCreateForm" role="form" novalidate class="form-validation">
<button type="button" class="btn btn-default" ng-click="vm.createNewDivePlan()">Create Plan</button>
</form>
</div>
</div>
<div class="row">
<table class="table">
<thead>
<tr>
<th>DivePlan Name</th>
<th>Autre</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="plan in vm.plans">
<td>{{plan.name}}</td>
<td>{{plan.name}}</td>
</tr>
</tbody>
</table>
</div>
</div>
I have a breakpoint in my JS code at the line divePlanService.createDivePlan(vm.divePlan); and a breakpoint in my DivePlanAppService when the function public void CreateDivePlan(CreateDivePlanInput input) is called. The issue I get is that the JS code executes but the DivePlanAppService function CreateDivePlan never executes, or at leave it never breaks at my breakpoint. The user interface shows the following:
I tried to simplify the code as much as I could. That's why the Service method doesn't do much so far. I noticed the constructor of DivePlanAppService is never called whereas the constructor of UserAppService is called whenever I navigate to the /#/users page.
What did I miss? Am I not providing the CreateDivePlanInput in the proper format? I tried to copy how TenantAppService works. Thanks in advance.
EDIT: I went to dig and debug in the CastleDynamicInterceptor and found this error message regarding my DivePlanAppService:
Some dependencies of this component could not be statically resolved. 'PlanMyDive.DivePlan.DivePlanAppService' is waiting for the following dependencies: - Service 'Abp.Domain.Repositories.IRepository`1[[PlanMyDive.DivePlan.DivePlan, PlanMyDive.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' which was not registered.
Upvotes: 0
Views: 248
Reputation: 9634
You have to add DivePlan to DbContext
public class PlanMyDiveDbContext : AbpDbContext
{
//other entities
public virtual IDbSet<DivePlan> DivePlans { get; set; }
...
}
Upvotes: 0