【问题标题】:AspNet boilerplate - AspNetZero - dependency injectionAspNet 样板 - AspNetZero - 依赖注入
【发布时间】:2018-06-17 19:59:47
【问题描述】:

我有以下类,我正在尝试实现依赖注入以在 ASP.NET 零中调用 WCF 服务。

接口IUserProxyService用CreateUser方法实现IApplicationService。

类 UserProxyService 通过 IUserRepository 的构造注入实现 IUserProxyService 并具有 CreateUser 方法。

接口 IUserRepository 指定实现 CreateUser 方法。

类 UserRespository 用没有参数的公共构造函数实现 IUserRepository 发起对 WCF 服务客户端的调用和另一个用于模拟的构造函数。此类包含对 WCF 服务的实际调用。

通过使用 IApplicationService,根据文档,CastleWindsor 在 ASPNetZero 中自动注册了我的课程。 现在,在 Authorisation.User(应用程序项目)的 UserAppService 类中。我将 IUserProxyService 作为附加参数添加到构造函数中。这样我就可以使用该对象进行 createuser 调用。

但是,在这样做之后,当我在 Web 应用程序上加载“用户”部分时,我收到了一个 javascript 错误:

 _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 中:

 //Manage linked accounts
 var _userLinkService = abp.services.app.userLink; - erroring line

我做错了什么?你能指引我正确的方向吗? 回复

【问题讨论】:

  • 看起来 abp.services.appundefined
  • 检查Logs.txt中的错误。

标签: javascript c# .net dependency-injection aspnetboilerplate


【解决方案1】:

我有同样的问题。检查此项目可能会纠正此错误。

1- AssetApplicationService 必须由 IApplicationService 实现。

 public interface IAssetApplicationService  : IApplicationService
 {   

 }
public class AssetApplicationService : IAssetApplicationService  
{   

}

2-检查您的模块加载是否正确,并在其他模块中添加正确的依赖项

    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"));
            }
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-28
    • 2011-04-08
    相关资源
    最近更新 更多