问题描述
我有以下课程,我正在尝试实现依赖注入以在ASP.NET Zero 0中调用WCF服务.
I have the following classes and I am trying to implement Dependency Injection into calling a WCF Service in ASP.NET Zero.
接口IUserProxyService通过CreateUser方法实现IApplicationService.
Interface IUserProxyService implements IApplicationService with CreateUser method.
UserProxyService类通过构造注入IUserRepository来实现IUserProxyService并具有CreateUser方法.
Class UserProxyService implments IUserProxyService with construction injection of IUserRepository and has a CreateUser Method.
接口IUserRepository指定实现CreateUser方法.
Interface IUserRepository specifies to implement CreateUser method.
类UserRespository的实现具有不带参数的公共构造函数的IUserRepository引发了对WCF服务客户端和另一个构造函数的调用,以进行模拟.此类包含对WCF服务的实际调用.
Class UserRespository implments IUserRepository with public constructor without parmaters intiates a call to the WCF Service Client and another constructor for mocking. This class contains the actual call to the WCF Service.
通过使用IApplicationService,根据文档,CastleWindsor在ASPNetZero中自动注册了我的课程.现在,在Authorisation.User(应用程序项目)的UserAppService类中.我将IUserProxyService添加为构造函数的附加参数.这样我就可以使用该对象进行createuser调用.
By Using IApplicationService, according to the documentation my class is automatically registered by CastleWindsor in ASPNetZero.Now, in UserAppService class in Authorisation.User(Application project). I am adding IUserProxyService as an additional parameter to my constructor. So that I can use that object to make createuser calls.
但是,这样做之后,当我在Web应用程序上加载用户"部分时,出现了JavaScript错误:
However, after doing this, when I load the Users section on the web application I am getting a javascript error:
_Header.js:74 Uncaught TypeError: Cannot read property 'app' of undefined
at HTMLDocument.<anonymous> (_Header.js:74)
at i (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at Function.ready (jquery.min.js:2)
at HTMLDocument.K (jquery.min.js:2)
在Header.js中:
In Header.js:
//Manage linked accounts
var _userLinkService = abp.services.app.userLink; - erroring line
我做错了什么?你能指引我正确的方向吗? 回覆
What am I doing wrong? Can you guide me in the right direction? Reply
推荐答案
我有同样的问题.检查此项目可能会纠正此错误.
I Have same Problem. check this items maybe correct this error.
1- AssetApplicationService必须由 IApplicationService 实现.
1- AssetApplicationService must be implemented by IApplicationService.
public interface IAssetApplicationService : IApplicationService
{
}
public class AssetApplicationService : IAssetApplicationService
{
}
2-检查您的模块是否正确加载,并在类似的其他模块中添加正确的依赖项.
2-check your module load correctly and add correct dependencies in other modules like this.
using System.Reflection;
using System.Web.Http;
using Abp.Application.Services;
using Abp.Configuration.Startup;
using Abp.Modules;
using Abp.WebApi;
namespace YourApp.Api
{
[DependsOn(typeof(AbpWebApiModule),
typeof(YourAppCommonModule),
typeof(YourAppApplicationModule))]
public class YourAppWebApiModule : AbpModule
{
public override void Initialize()
{
IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
Configuration.Modules.AbpWebApi().DynamicApiControllerBuilder
.ForAll<IApplicationService>(typeof(YourAppCommonModule).Assembly, "app")
.Build();
Configuration.Modules.AbpWebApi().DynamicApiControllerBuilder
.ForAll<IApplicationService>(typeof(YourAppApplicationModule).Assembly, "app")
.Build();
Configuration.Modules.AbpWebApi().HttpConfiguration.Filters.Add(new HostAuthenticationFilter("Bearer"));
}
}
}
这篇关于AspNet样板-AspNetZero-依赖项注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!