AspNet boilerplate - AspNetZero - dependency injection

匆匆过客 提交于 2019-12-13 05:06:29

问题


I have the following classes and I am trying to implement Dependency Injection into calling a WCF Service in ASP.NET Zero.

Interface IUserProxyService implements IApplicationService with CreateUser method.

Class UserProxyService implments IUserProxyService with construction injection of IUserRepository and has a CreateUser Method.

Interface IUserRepository specifies to implement CreateUser method.

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.

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.

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)

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


回答1:


I Have same Problem. check this items maybe correct this error.

1- AssetApplicationService must be implemented by IApplicationService.

 public interface IAssetApplicationService  : IApplicationService
 {   

 }
public class AssetApplicationService : IAssetApplicationService  
{   

}

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


来源:https://stackoverflow.com/questions/48157094/aspnet-boilerplate-aspnetzero-dependency-injection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!