• 学习ABP遇到的问题汇总


    1,在abp官网下载的模板(asp.net+ef)写Application层的时候需要使用AutoMapper。结果ObjectMapper一直为null

    解决:需要在当前项目的Module依赖AbpAutoMapperModule

    2,Linq Include扩展方法需要引用EntityFramework.dll

    3,ToListAsync扩展方法需要引用using Abp.Linq.Extensions;

    4,手动搭建abp2.x老是出现System.Collections.Immutable1.2.1.0找不到

    解决:

    ①编辑项目web.config改为(这个可以不管)

          <dependentAssembly>
            <assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-1.2.1.0" newVersion="1.2.1.0" />
          </dependentAssembly>

    ②编辑项目工程文件(例如Demo.Web.csproj文件)

     案例下载:http://pan.baidu.com/s/1kU7By31

    5,创建租户(独立数据库)报MSDTC 不可用

    解决方案:

    打开windows服务开启Distributed Transaction Coordinator服务

    6,单元测试时老是报个错:

    解决:

    单元测试Module需要依赖AbpTestBaseModule

    7,运行模板项目报错

    解决办法:删除项目下的bin目录,然后重新编译就好了

    8, 把Abp.Zero.Common添加到项目报错

    解决方法:

    在Abp.Zero.Common.csproj文件中删除

    9,本地化失效

    解决方法:需要把xml设置为嵌入的资源

    10,更改提示变成中文 

    扩展本地化文件

    在Ousutec.Duty.Core中的DutyLocalizationConfigurer的Configure方法加上扩展配置

    using Abp.Configuration.Startup;
    using Abp.Localization.Dictionaries;
    using Abp.Localization.Dictionaries.Xml;
    using Abp.Localization.Sources;
    using Abp.Reflection.Extensions;
    
    namespace Ousutec.Duty.Localization
    {
        public static class DutyLocalizationConfigurer
        {
            public static void Configure(ILocalizationConfiguration localizationConfiguration)
            {
                localizationConfiguration.Sources.Add(
                    new DictionaryBasedLocalizationSource(DutyConsts.LocalizationSourceName,
                        new XmlEmbeddedFileLocalizationDictionaryProvider(
                            typeof(DutyLocalizationConfigurer).GetAssembly(),
                            "Ousutec.Duty.Localization.SourceFiles"
                        )
                    )
                );
    
                localizationConfiguration.Sources.Extensions.Add(
                    new LocalizationSourceExtensionInfo("AbpWeb",
                        new XmlEmbeddedFileLocalizationDictionaryProvider(
                            typeof(DutyLocalizationConfigurer).GetAssembly(),
                            "Ousutec.Duty.Localization.AbpWebExtensions"
                            )
                        )
                    );
            }
        }
    }
    DutyLocalizationConfigurer

    将Abp.Web.Common源码的AbpWeb-zh-Hans.xml复制到Ousutec.Duty.Core项目中。并嵌入资源

    11,关于自动注册依赖

    约定名称必须一直,例如

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Castle.Core.Logging;
    using Ousutec.Duty.Common;
    using Newtonsoft.Json;
    
    using Abp.Dependency;
    using Ousutec.Duty.DutyCmds;
    using Abp.AutoMapper;
    
    namespace Ousutec.Duty.RabbitMqListeners
    {
        public class DutyCmdListener : IDutyCmdListener, ITransientDependency
        {
            private readonly ILogger _logger;
            private readonly IDutyCmdAppService _dutyCmdAppService;
            public DutyCmdListener(ILogger logger, IDutyCmdAppService dutyCmdAppService)
            {
                _logger = logger;
                _dutyCmdAppService = dutyCmdAppService;
            }
    
            public void ProcessMsg(DutyCmdMessage msg)
            {
                _logger.Info(JsonConvert.SerializeObject(msg));
                _dutyCmdAppService.Add(msg.DutyCmdDtos.MapTo<IEnumerable<Addinput>>());
            }
        }
    }
    DutyCmdListener

    不一致会 报找不到依赖异常

    12,Swagger CustomSchemaIds错误

    Conflicting schemaIds: Identical schemaIds detected for types Ousutec.Duty.DutyRecords.AddInput and Ousutec.Duty.DutyDevSettings.AddInput. See config settings - "CustomSchemaIds" for a workaround

    解决方法:  options.CustomSchemaIds(t => t.FullName); 

                // Swagger - Enable this line and the related lines in Configure method to enable swagger UI
                services.AddSwaggerGen(options =>
                {
                    options.SwaggerDoc("v1", new Info { Title = "Duty API", Version = "v1" });
                    options.DocInclusionPredicate((docName, description) => true);
    
                    options.CustomSchemaIds(t => t.FullName);
                    // Define the BearerAuth scheme that's in use
                    options.AddSecurityDefinition("bearerAuth", new ApiKeyScheme()
                    {
                        Description = "JWT Authorization header using the Bearer scheme. Example: "Authorization: Bearer {token}"",
                        Name = "Authorization",
                        In = "header",
                        Type = "apiKey"
                    });
                    // Assign scope requirements to operations based on AuthorizeAttribute
                    options.OperationFilter<SecurityRequirementsOperationFilter>();
                });
    Startup

    13,接口返回参数命名,忽略abp框架设置的命名规则

    using System;
    using System.Linq;
    using System.Reflection;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Mvc.Cors.Internal;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Castle.Facilities.Logging;
    using Swashbuckle.AspNetCore.Swagger;
    using Abp.AspNetCore;
    using Abp.Castle.Logging.Log4Net;
    using Abp.Extensions;
    using Ousu.DataCollection.Attendance.Authentication.JwtBearer;
    using Ousu.DataCollection.Attendance.Configuration;
    using Ousu.DataCollection.Attendance.Identity;
    using Ousu.DataCollection.Attendance.Common;
    using Abp.AspNetCore.SignalR.Hubs;
    using Ousu.DataCollection.Attendance.AttendanceCmds;
    using Abp.Dependency;
    using Castle.Windsor.MsDependencyInjection;
    using Aliyun.OSS;
    using Castle.Core.Logging;
    using Abp.Json;
    using Newtonsoft.Json.Serialization;
    using Abp;
    
    namespace Ousu.DataCollection.Attendance.Web.Host.Startup
    {
        public class Startup
        {
            private const string _defaultCorsPolicyName = "localhost";
    
            private readonly IConfigurationRoot _appConfiguration;
    
    
            public Startup(IHostingEnvironment env)
            {
                _appConfiguration = env.GetAppConfiguration();
            }
    
            public IServiceProvider ConfigureServices(IServiceCollection services)
            {
    
                // MVC
                services.AddMvc(
                    options =>
                    {
                        options.Filters.Add(new CorsAuthorizationFilterFactory(_defaultCorsPolicyName));
                    }
                );
    
                IdentityRegistrar.Register(services);
                AuthConfigurer.Configure(services, _appConfiguration);
    
                services.AddSignalR();
    
                // Configure CORS for angular2 UI
                services.AddCors(
                    options => options.AddPolicy(
                        _defaultCorsPolicyName,
                        builder => builder
                            .WithOrigins(
                                // App:CorsOrigins in appsettings.json can contain more than one address separated by comma.
                                _appConfiguration["App:CorsOrigins"]
                                    .Split(",", StringSplitOptions.RemoveEmptyEntries)
                                    .Select(o => o.RemovePostFix("/"))
                                    .ToArray()
                            )
                            .AllowAnyHeader()
                            .AllowAnyMethod()
                            .AllowCredentials()
                    )
                );
    
                // Swagger - Enable this line and the related lines in Configure method to enable swagger UI
                services.AddSwaggerGen(options =>
                {
                    options.SwaggerDoc("v1", new Info { Title = "Attendance API", Version = "v1" });
                    options.DocInclusionPredicate((docName, description) => true);
    
                    options.CustomSchemaIds(t => t.FullName);
                    // Define the BearerAuth scheme that's in use
                    options.AddSecurityDefinition("bearerAuth", new ApiKeyScheme()
                    {
                        Description = "JWT Authorization header using the Bearer scheme. Example: "Authorization: Bearer {token}"",
                        Name = "Authorization",
                        In = "header",
                        Type = "apiKey"
                    });
                    // Assign scope requirements to operations based on AuthorizeAttribute
                    options.OperationFilter<SecurityRequirementsOperationFilter>();
                });
    
                //去除abp框架自带的命名规则
                services.PostConfigure<MvcJsonOptions>(options =>
                {
                    options.SerializerSettings.ContractResolver = new AbpContractResolver();
                });
    
                // Configure Abp and Dependency Injection 
                return services.AddAbp<AttendanceWebHostModule>(
                    // Configure Log4Net logging
                    options =>
                    {
                        options.IocManager.IocContainer.AddFacility<LoggingFacility>(f => f.UseAbpLog4Net().WithConfig("log4net.config"));
                    }
                );
            }
    
            public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
            {
                app.UseAbp(options => { options.UseAbpRequestLocalization = false;}); // Initializes ABP framework.
    
                app.UseCors(_defaultCorsPolicyName); // Enable CORS!
    
                app.UseStaticFiles();
    
                app.UseAuthentication();
    
                app.UseAbpRequestLocalization();
    
                app.UseSignalR(routes =>
                {
                    routes.MapHub<AbpCommonHub>("/signalr");
                });
    
                app.UseMvc(routes =>
                {
                    routes.MapRoute(
                        name: "defaultWithArea",
                        template: "{area}/{controller=Home}/{action=Index}/{id?}");
    
                    routes.MapRoute(
                        name: "default",
                        template: "{controller=Home}/{action=Index}/{id?}");
                });
    
                // Enable middleware to serve generated Swagger as a JSON endpoint
                app.UseSwagger();
                // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.)
                app.UseSwaggerUI(options =>
                {
                    options.SwaggerEndpoint(_appConfiguration["App:ServerRootAddress"] + "/swagger/v1/swagger.json", "Attendance API V1");
                    options.IndexStream = () => Assembly.GetExecutingAssembly()
                        .GetManifestResourceStream("Ousu.DataCollection.Attendance.Web.Host.wwwroot.swagger.ui.index.html");
                }); // URL: /swagger
            }
        }
    }
    去除abp框架自带的命名规则

    14,不使用abp框架自带的返回格式

    在类或者方法上加上[DontWrapResult]特性

  • 相关阅读:
    HOWTO: IE8下处理iframe自适应高度
    脚印:记录一次重构,将规则生产和规则消费(执行委托)分离
    Microsoft ASP.NET 2.0 AJAX 相关信息备忘
    脚印:软件开发随想录
    脚印:关于扩展方法的使用
    MVC 模式在javascript中的应用
    2007年总结
    下拉框自动回发!
    国庆前生活学习计划
    看完色戒有感
  • 原文地址:https://www.cnblogs.com/zd1994/p/7479419.html
Copyright © 2020-2023  润新知