DI注册服务类型.net core 3.0

编程入门 行业动态 更新时间:2024-10-17 21:28:28
本文介绍了DI注册服务类型 core 3.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个n层分层的应用程序,并且在基础结构模块中,我试图开发发送电子邮件以确认用户的程序,但出现错误。

I have one n-tier layered app and in Infrastructure module where I'm trying to develop sending email for confirmation an user, I'm getting an error.

没有类型的服务'IMS.Infrastructure.Helpers.CustomEmailConfirmationTokenProvider`1 [Microsoft.AspNetCore.Identity.IdentityUser]'已注册。

No service for type 'IMS.Infrastructure.Helpers.CustomEmailConfirmationTokenProvider`1[Microsoft.AspNetCore.Identity.IdentityUser]' has been registered.

根据代码,我接下来要做的是:

From code what I had did is next:

public class CustomEmailConfirmationTokenProvider<TUser> : DataProtectorTokenProvider<TUser> where TUser : class { public CustomEmailConfirmationTokenProvider(IDataProtectionProvider dataProtectionProvider, IOptions<DataProtectionTokenProviderOptions> options, ILogger<DataProtectorTokenProvider<TUser>> logger) : base(dataProtectionProvider, options) { } }

并用于创建服务:

services.AddDbContext<ApplicationIdentityDbContext>(options => options.UseSqlServer(configuration.GetConnectionString("Default"))); services.AddIdentityCore<ApplicationUser>(options => { options.Password.RequireDigit = false; options.Password.RequireLowercase = false; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = false; options.Password.RequiredLength = 4; options.SignIn.RequireConfirmedEmail = true; options.Tokens.ProviderMap.Add("CustomEmailConfirmation", new TokenProviderDescriptor( typeof(CustomEmailConfirmationTokenProvider<IdentityUser>))); options.Tokens.EmailConfirmationTokenProvider = "CustomEmailConfirmation"; }) .AddEntityFrameworkStores<ApplicationIdentityDbContext>(); services.AddTransient<CustomEmailConfirmationTokenProvider<ApplicationUser>>(o => { var service = new CustomEmailConfirmationTokenProvider<ApplicationUser>(o.GetService<IDataProtectionProvider>(), o.GetService<IOptions<DataProtectionTokenProviderOptions>>(), o.GetService<ILogger<DataProtectorTokenProvider<ApplicationUser>>>()); return service; });

我将需要帮助来了解如何未注册CustomEmailConfirmationTokenProvider服务,我做错了什么?

I will need help to understand how service CustomEmailConfirmationTokenProvider is not registered, what I had did wrong ?

亲切的问候, Danijel

Kind Regards, Danijel

推荐答案

容器 CustomEmailConfirmationTokenProvider< ApplicationUser> 和 CustomEmailConfirmationTokenProvider< IdentityUser> 是两个不同且不相关的类。

From perspective of IoC container CustomEmailConfirmationTokenProvider<ApplicationUser> and CustomEmailConfirmationTokenProvider<IdentityUser> are two different and unrelated classes.

您应该同时具有使用和注册权限,才能拥有相同类型的用户。

You should have both usage and registration to have same type of user.

更多推荐

DI注册服务类型.net core 3.0

本文发布于:2023-11-14 04:15:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586186.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类型   DI   net   core

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!