在领域事件中调用UserRegistrationManager.RegisterAsync抛异常

Call UserRegistrationManager.RegisterAsync() throw exception in a domain event

//在github请求帮助之前.
//
//先去:https://stackoverflow.com/questions/tagged/aspnetboilerplate 看看有没有相应的问题
public class EventCreateUser : MainxxDomainServiceBase, IEventHandler<Records.Events.AddUserRecordEventData>, ITransientDependency
{
private readonly UserRegistrationManager _userRegistrationManager;
private readonly IUnitOfWorkManager _unitOfWorkManager; public EventCreateUser(
IUnitOfWorkManager unitOfWorkManager,
UserRegistrationManager userRegistrationManager)
{
_userRegistrationManager = userRegistrationManager;
_unitOfWorkManager = unitOfWorkManager;
}
public async void HandleEvent(AddUserRecordEventData eventData)
{
var user = await _userRegistrationManager.RegisterAsync(
eventData.AddUserRecordData.UserName,
eventData.AddUserRecordData.UserName,
eventData.AddUserRecordData.UserName + "@test.core",
eventData.AddUserRecordData.UserName,
eventData.AddUserRecordData.Password,
true, null);
}
}

Error Massage

System.ObjectDisposedException
HResult=0x80131622
Message=Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling Dispose() on the context, or wrapping the context in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances.Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling Dispose() on the context, or wrapping the context in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances.
Source=Microsoft.EntityFrameworkCore
StackTrace:
at Microsoft.EntityFrameworkCore.DbContext.CheckDisposed()
at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
at Microsoft.EntityFrameworkCore.DbContext.get_Model()
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.get_EntityType()
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.get_EntityQueryable()
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.System.Linq.IQueryable.get_Provider()
at System.Linq.Queryable.Where[TSource](IQueryable`1 source, Expression`1 predicate)
at Mainxx.Authorization.Users.UserRegistrationManager.<RegisterAsync>d__13.MoveNext() in S:\Gitee\Mainxx\aspnet-core\src\Mainxx.Core\Authorization\Users\UserRegistrationManager.cs:line 82
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

解决方案:

Github issuse:https://github.com/aspnetboilerplate/aspnetboilerplate/issues/3544#issuecomment-399766719

  • Add [UnitOfWork] attribute.
  • Make method virtual.
  • Implement IAsyncEventHandler if async.
  • [UnitOfWork]
  • public virtual async Task HandleEventAsync(AddUserRecordEventData eventData)

ABP在领域事件中异步调用方法抛异常的更多相关文章

  1. jquery ajax success 函数 异步调用方法中不能给全局变量赋值的原因及解决办法

    jquery ajax success 函数 异步调用方法中不能给全局变量赋值的原因及解决办法   在调用一个jquery的ajax方法时我们有时会需要该方法返回一个值或者给某个全局变量赋值,可是我们 ...

  2. NET中级课--浅谈委托,事件,异步调用,回调等概念

    直接说题. 委托         首先明确它是什么,其实就是一个类,定义一个委托即定义一个类,那么它是什么类?用来说明方法的类型的类.字段有类型,那么方法其实也有类型,就是委托.       委托是某 ...

  3. echarts异步数据加载(在下拉框选择事件中异步更新数据)

    接触echarts 大半年了,从不会到熟练也做过不少的图表,隔了一段时间没使用这玩意,好多东西真心容易忘了.在接触echarts这期间也没有总结什么东西,今天我就来总结一下如何在echart中异步加载 ...

  4. php异步调用方法实现示例

    php 异步调用方法   客户端与服务器端是通过HTTP协议进行连接通讯,客户端发起请求,服务器端接收到请求后执行处理,并返回处理结果.   有时服务器需要执行很耗时的操作,这个操作的结果并不需要返回 ...

  5. 微信小程序:封装全局的promise异步调用方法

    微信小程序:封装全局的promise异步调用方法 一:封装 function POST(url, params) { let promise = new Promise(function (resol ...

  6. SpringBoot 异步调用方法并接收返回值

    项目中肯定会遇到异步调用其他方法的场景,比如有个计算过程,需要计算很多个指标的值,但是每个指标计算的效率快慢不同,如果采用同步执行的方式,运行这一个过程的时间是计算所有指标的时间之和.比如: 方法A: ...

  7. C#中运用事件实现异步调用

    问题引出: winform程序中的耗时操作,一般不能在UI线程中执行,需要另开线程.往往我们需要在耗时操作结束后将结果显示在UI上. 以下是Mainform.cs中调用耗时操作的一段代码: Job j ...

  8. 浅析jquery ajax异步调用方法中不能给全局变量赋值的原因及解决方法(转载)

    在调用一个jquery的ajax方法时我们有时会需要该方法返回一个值或者给某个全局变量赋值,可是我们发现程序执行完后并没有获取到我们想要的值,这时很有可能是因为你用的是ajax的异步调用async:t ...

  9. ABP框架 - 领域事件(EventBus)

    文档目录 本节内容: EventBus 注入 IEventBus 获取默认实例 定义事件 预定义事件 处理完异常 实体修改 触发事件 处理事件 处理基类事件 处理程序异常 处理多个事件 处理程序注册 ...

随机推荐

  1. Tomcat的学习和使用(一)

    一.Tomcat服务器端口的配置 Tomcat的所有配置都放在conf文件夹之中,里面的server.xml文件是配置的核心文件. 如果想修改Tomcat服务器的启动端口,则可以在server.xml ...

  2. Visual Studio Code插件

    Material Theme 下载量:130 万 Visual Studio Code 最悠久的主题! Auto Import 下载量:46 万 自动去查找.分析.然后提供代码补全.对于 TypeSc ...

  3. Angular进阶教程二

    6.2自定义指令详解 angular的指令机制.angular通过指令的方式实现了HTML的扩展,增强后的HTML不仅长相焕然一新,同时也获得了很多强大的技能.更厉害的是,你还可以自定义指令,这就意味 ...

  4. 【vue入门】日志demo,增删改查的练习(无vuex版本)

    安装 1. 确定电脑已装node和npm 出现版本号则说明电脑已经安装好node和npm2. 创建一个基于webpack的项目   3. 在项目里安装依赖 4. 运行 配置路由为了动态渲染各个页面的组 ...

  5. LintCode2016年8月22日算法比赛----克隆二叉树

    克隆二叉树 题目描述 深度复制一个二叉树. 给定一个二叉树,返回一个它的克隆品. 样例 给定一个二叉树: 1 / \ 2 3 / \ 4 5 返回其相同结构相同数值的克隆二叉树: 1 / \ 2 3 ...

  6. vue学习(一)、Vue.js简介

    Vue.js 五天 汤小洋一. Vue.js简介1. Vue.js是什么Vue.js也称为Vue,读音/vju:/,类似view,错误读音v-u-e 版本:v1.0 v2.0 是一个构建用户界面的框架 ...

  7. visual studio code 插入当前时间插件 -- Insert Time Stamp

    使用方法:ctrl + f5 效果:

  8. MySQL Database on Azure服务在中国正式商用

    基于由世纪互联运营的Windows Azure平台,MySQL Database on Azure服务助力中国用户实现数据库在云端的快速部署.推进用户的创新开发 2015年9月10日,北京——微软中国 ...

  9. CC150相关问题

    18.9 动态计算中位数 利用两个堆:一个最大堆,存放小于中位数的值:一个最小堆,存放大于中位数的值. 则两个堆的堆顶即为数组中最中间的两个数. 在插入新元素的时候,我们只要维护两个堆, 使其堆中元素 ...

  10. select server

    server with select #include<stdio.h> #include<sys/types.h> #include<sys/socket.h> ...