在.NET Core 2.0中使用Dapper替代Identity默认存储
在ASP.NET Core 2.0中,开发人员可以通过Dapper替代Identity的默认Entity Framework存储,从而提高性能和灵活性。首先,在Startup.cs
中添加Identity服务:
services.AddIdentity()
.AddDefaultTokenProviders();
然后,注册自定义存储:
services.AddTransient, CustomUserStore>();
services.AddTransient, CustomRoleStore>();
接着,配置数据库连接并注入SqlConnection
:
string connectionString = Configuration.GetConnectionString("SqlConnectionStr");
services.AddTransient(e => new SqlConnection(connectionString));
实现CustomUserStore
和CustomRoleStore
类,遵循Identity框架接口,使用Dapper进行数据库操作,确保数据一致性及事务处理。
21.83KB
文件大小:
评论区