我下载了带有 AngularJS 和实体框架的 ASP.NET MVC,模块零示例。我添加了一个名为 DivePlan 的实体,现在只有一个字符串属性名称。
namespace PlanMyDive.DivePlan
{
public class DivePlan : Entity
{
public virtual string Name { get; set; }
public DivePlan() { }
public DivePlan(string name)
{
this.Name = name;
}
}
}
然后我在应用层创建了一个服务:
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);
}
}
最后,我在 Angular 路由中添加了一个页面 Plans,实现如下:
(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>
我的 JS 代码中有一个断点,位于 divePlanService.createDivePlan(vm.divePlan); 行。以及调用函数 public void CreateDivePlan(CreateDivePlanInput input) 时我的 DivePlanAppService 中的断点。我得到的问题是 JS 代码执行但 DivePlanAppService 函数 CreateDivePlan 永远不会执行,或者离开它永远不会在我的断点处中断。用户界面显示以下内容:
我试图尽可能地简化代码。这就是为什么 Service 方法到目前为止没有做太多事情的原因。我注意到 DivePlanAppService 的构造函数从未被调用,而 UserAppService 的构造函数在我导航到 /#/users 页面时被调用。
我错过了什么?我没有以正确的格式提供 CreateDivePlanInput 吗?我试图复制 TenantAppService 的工作方式。提前致谢。
编辑:我在 CastleDynamicInterceptor 中进行挖掘和调试,发现有关我的 DivePlanAppService 的错误消息:
此组件的某些依赖项无法静态解析。'PlanMyDive.DivePlan.DivePlanAppService' 正在等待以下依赖项: - 服务 'Abp.Domain.Repositories.IRepository`1[[PlanMyDive.DivePlan.DivePlan, PlanMyDive.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken= null]]' 未注册。