小编Don*_*ain的帖子

APIGatewayProxyFunction 的空引用异常

我终于设法让我的 API 进入可以将其上传到 AWS Lambda 的状态,然后每当我尝试使用 API Gateway 测试它时,都会收到以下错误。

{
  "errorType": "AggregateException",
  "errorMessage": "One or more errors occurred. (Object reference not set to an instance of an object.)",
  "stackTrace": [
    "at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)",
    "at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)",
    "at lambda_method(Closure , Stream , Stream , ContextInfo )"
  ],
  "cause": {
    "errorType": "NullReferenceException",
    "errorMessage": "Object reference not set to an instance of an object.",
    "stackTrace": [
      "at Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction.MarshallRequest(InvokeFeatures features, APIGatewayProxyRequest apiGatewayRequest)",
      "at Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction.<FunctionHandlerAsync>d__12.MoveNext()"
    ]
  }
}

Run Code Online (Sandbox Code Playgroud)

代码:

public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
{ …
Run Code Online (Sandbox Code Playgroud)

c# amazon-web-services aws-lambda aws-api-gateway asp.net-core

6
推荐指数
1
解决办法
5565
查看次数

在集成测试中使用IMapper

正如标题所说,我正在编写集成测试,并希望测试和初始化IMapper对象作为这些测试的一部分.

我使用XUnit作为测试框架,使用Ninject来处理依赖注入.

我习惯使用静态AutoMapper方法,并转而使用IMapper接口,这是我的一个存储库构造函数中的参数.

我有一个继承NinjectModule基类的DependencyRegistrar类.

我的加载方法如下:

public override void Load()
    {
        var automapperConfig = new MapperConfiguration(cfg => { cfg.AddProfile<AutoMapperProfile>(); });
        automapperConfig.AssertConfigurationIsValid();
        var mapper = automapperConfig.CreateMapper();

        Bind<IMapper>().ToConstant(mapper).InSingletonScope();
        Bind<IUserManager>().To<UserManager>().InTransientScope();
        Bind<IUserRepository>().To<UserRepository>().InTransientScope();
    }
Run Code Online (Sandbox Code Playgroud)

该模块由API项目中的NinjectWebCommon类加载,但显然在集成测试期间不会加载.

ConfigurationSettingsEntity configurationSettings = new ConfigurationSettingsEntity(ConfigurationManager.AppSettings);
        var modules = new INinjectModule[] { new DependencyResolution.DependencyRegistrar(configurationSettings) };
        var kernel = new StandardKernel(modules);
Run Code Online (Sandbox Code Playgroud)

所以,我的问题是,加载真正的映射器实现的最佳方法是什么,以便在构建集成测试时我可以将该映射器传递到我的存储库的构造函数中?

UserRepository tester = new UserRepository(mapper);
Run Code Online (Sandbox Code Playgroud)

integration ninject xunit automapper

3
推荐指数
1
解决办法
508
查看次数

自动映射器舍入所有十进制类型实例

我需要一种方法来向我的自动映射器配置添加舍入。我尝试按照此处的建议使用 IValueFormatter:Automapper 将小数设置为全部为 2 位小数

但 AutoMapper 不再支持格式化程序。我不需要将其转换为不同的类型,所以我也不确定类型转换器是最好的解决方案。

现在还有一个好的 automapper 解决这个问题吗?

使用 AutoMapper 版本 6.11

c# automapper automapper-6

2
推荐指数
1
解决办法
3029
查看次数