【发布时间】:2022-11-09 01:54:29
【问题描述】:
我需要使用 Amazon SES 在 .net 6 中发送电子邮件。
在 .net 5 中以及在您需要将其添加到 startup.cs 之前
// Amazon SES
services.AddDefaultAWSOptions(Configuration.GetAWSOptions());
services.AddAWSService<IAmazonSimpleEmailService>();
services.AddSingleton<IEmailService, CSharpAwsSesServiceHelper.EmailService.AwsEmailService>();
services.Configure<AwsEmailServiceOptions>(Configuration.GetSection(nameof(AwsEmailServiceOptions)))
.AddSingleton(x => x.GetRequiredService<IOptions<AwsEmailServiceOptions>>().Value);
在 .net 6 中没有 Startup.cs,它已在 program.cs 中被替换和简化。
但是,在 program.cs 中默认没有配置对象,就像在 Startup.cs 中一样,这不起作用(错误'配置不包含 GetAWSOptions())
我搜索了一个示例项目或指导,例如 https://aws.amazon.com/blogs/developer/net-6-on-aws/
https://github.com/aws-samples/aws-net-guides/tree/master/RuntimeSupport/dotnet6
但找不到此代码的 .net 6 版本。
有人知道这里有什么最佳实践/如何使这项工作有效吗?
谢谢。
更新
我已将所有 using 语句从 Startup.cs 复制到 Program.cs - 这不是问题。
然后,我复制了服务构建器(将服务更改为 builder.Services。)由于 program.cs 中缺少配置对象,我收到上面列出的错误。
【问题讨论】:
-
“这不起作用”什么是“这个”?最明显的解决方案是添加缺少的
using语句 -
您必须在 Program.cs 中配置服务,对吧?它与 Startup 中的服务构建器相同。
-
我已经更新了问题以澄清这些观点。
标签: c# amazon-ses .net-6.0