Giter Club home page Giter Club logo

netpro's Issues

多语言库移除默认后缀

目前使用多语言库时,直接指定key取对应文本,当key不存在时,会返回一个computedKey,即带有语言后缀的key,原因见:

https://github.com/damienbod/AspNetCoreLocalization/blob/3e88aa6701cde503e1595d529e27770fb0e98f50/src/Localization.SqlLocalizer/DbStringLocalizer/SqlStringLocalizer.cs#L67

建议调整传入Localization.SqlLocalizer的选项,使其在没有对应key的时候直接返回key,当项目需要支持多语言时,则手动增加各种语言对应的信息

关于异常:Unable to resolve service for type 'Microsoft.AspNetCore.Http.IHttpContextAccessor

完整错误信息:
Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: IDasContextAccessor Lifetime: Singleton ImplementationType: Das.Common.DasContextAccessor': Unable to resolve service for type 'Microsoft.AspNetCore.Http.IHttpContextAccessor' while attempting to activate 'Das.Common.DasContextAccessor'.)

InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Http.IHttpContextAccessor' while attempting to activate 'Das.Common.DasContextAccessor

原因分析:
经调试后发现是项目中 NetPro.Web.Api中 RoutingStartup 执行报错导致 RoutingStartup 未能正确执行完毕,从而引起IHttpContextAccessor未被注入,最终导致这个问题的出现。在将 library中NetPro.Web.Api项目的RoutingStartup 源码拷贝下来执行调试后查看错误信息发现是这段代码报错了

mvcBuilder.AddFluentValidation(configuration =>           
{
                string assemblySkipLoadingPattern = "^NetPro.*|^Com.Ctrip*|^Figgle|^Serilog.*|^netstandard|^OpenTracing.Contrib.NetCor|^App.Metrics.AspNetCore|^SkyAPM|^Swashbuckle|^System|^mscorlib|^Microsoft|^AjaxControlToolkit|^Antlr3|^Autofac|^AutoMapper|^Castle|^ComponentArt|^CppCodeProvider|^DotNetOpenAuth|^EntityFramework|^EPPlus|^FluentValidation|^ImageResizer|^itextsharp|^log4net|^MaxMind|^MbUnit|^MiniProfiler|^Mono.Math|^MvcContrib|^Newtonsoft|^NHibernate|^nunit|^Org.Mentalis|^PerlRegex|^QuickGraph|^Recaptcha|^Remotion|^RestSharp|^Rhino|^Telerik|^Iesi|^TestDriven|^TestFu|^UserAgentStringLibrary|^VJSharpCodeProvider|^WebActivator|^WebDev|^WebGrease";
                var assembliesResult = new List<Assembly>();
                foreach (var item in assemblies)
                {
                    if (!Regex.IsMatch(item.FullName, assemblySkipLoadingPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled) && Regex.IsMatch(item.FullName, ".*", RegexOptions.IgnoreCase | RegexOptions.Compiled))
                    {
                        if (!item.IsDynamic)
                            assembliesResult.Add(item);
                    }
                }
                configuration.RegisterValidatorsFromAssemblies(assembliesResult);

                //implicit/automatic validation of child properties 复合对象是否验证
                configuration.ImplicitlyValidateChildProperties = true;
 });

原因是NetPro本身有一个版本的SQLLite程序集,我在使用时又引入了SQLLite的其他版本程序集,而这里的正则表达式又没有排除搜索这两个,所以导致在注册的时候出现冲突

解决办法:
在配置文件中添加

"TypeFinderOption": { "CustomDllPattern": "^XXX.Api*" }

此配置表示仅搜索正则匹配到的程序集,此时只有一个版本的SQLLite,不再报错,问题解决。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.