ABP在领域事件中异步调用方法抛异常
在领域事件中调用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在领域事件中异步调用方法抛异常的更多相关文章
- jquery ajax success 函数 异步调用方法中不能给全局变量赋值的原因及解决办法
jquery ajax success 函数 异步调用方法中不能给全局变量赋值的原因及解决办法 在调用一个jquery的ajax方法时我们有时会需要该方法返回一个值或者给某个全局变量赋值,可是我们 ...
- NET中级课--浅谈委托,事件,异步调用,回调等概念
直接说题. 委托 首先明确它是什么,其实就是一个类,定义一个委托即定义一个类,那么它是什么类?用来说明方法的类型的类.字段有类型,那么方法其实也有类型,就是委托. 委托是某 ...
- echarts异步数据加载(在下拉框选择事件中异步更新数据)
接触echarts 大半年了,从不会到熟练也做过不少的图表,隔了一段时间没使用这玩意,好多东西真心容易忘了.在接触echarts这期间也没有总结什么东西,今天我就来总结一下如何在echart中异步加载 ...
- php异步调用方法实现示例
php 异步调用方法 客户端与服务器端是通过HTTP协议进行连接通讯,客户端发起请求,服务器端接收到请求后执行处理,并返回处理结果. 有时服务器需要执行很耗时的操作,这个操作的结果并不需要返回 ...
- 微信小程序:封装全局的promise异步调用方法
微信小程序:封装全局的promise异步调用方法 一:封装 function POST(url, params) { let promise = new Promise(function (resol ...
- SpringBoot 异步调用方法并接收返回值
项目中肯定会遇到异步调用其他方法的场景,比如有个计算过程,需要计算很多个指标的值,但是每个指标计算的效率快慢不同,如果采用同步执行的方式,运行这一个过程的时间是计算所有指标的时间之和.比如: 方法A: ...
- C#中运用事件实现异步调用
问题引出: winform程序中的耗时操作,一般不能在UI线程中执行,需要另开线程.往往我们需要在耗时操作结束后将结果显示在UI上. 以下是Mainform.cs中调用耗时操作的一段代码: Job j ...
- 浅析jquery ajax异步调用方法中不能给全局变量赋值的原因及解决方法(转载)
在调用一个jquery的ajax方法时我们有时会需要该方法返回一个值或者给某个全局变量赋值,可是我们发现程序执行完后并没有获取到我们想要的值,这时很有可能是因为你用的是ajax的异步调用async:t ...
- ABP框架 - 领域事件(EventBus)
文档目录 本节内容: EventBus 注入 IEventBus 获取默认实例 定义事件 预定义事件 处理完异常 实体修改 触发事件 处理事件 处理基类事件 处理程序异常 处理多个事件 处理程序注册 ...
随机推荐
- 利用Ogr将Kml转为Shape【1】
最近在研究Kml怎么转化为Shape文件,因为客户中很多在原来采集了一部分数据都是在google Earth中,而我们的应用中特别需要这份数据,所以打算先在GE中把这份数据导出为Kml或Kmz文件,然 ...
- JavaScript : Array assignment creates reference not copy
JavaScript : Array assignment creates reference not copy 29 May 2015 Consider we have an array var a ...
- 一步一步pwn路由器之栈溢出实战
前言 本文由 本人 首发于 先知安全技术社区: https://xianzhi.aliyun.com/forum/user/5274 本文以 DVRF 中的第一个漏洞程序 stack_bof_01 为 ...
- Android碎笔录1——基本布局
刚开始学Android开发的时候,没有H5的基础总是分不清android布局文件的用法,真正要学会android布局还是得实战一次,下面不多说,直接上代码. 这是一个登陆界面,LinerLayout嵌 ...
- 自学git心得-4
本节介绍分支的一些具体应用实例. 1.Bug分支 设想我们正在分支dev上工作,突然接到一个修复bug的命令,我们需要创建分支issue-101来修复它,在此之前我们肯定需要先保存我们当前未完成的工作 ...
- 打印 1 到最大的 n 位数(C++ 和 Python 实现)
(说明:本博客中的题目.题目详细说明及参考代码均摘自 “何海涛<剑指Offer:名企面试官精讲典型编程题>2012年”) 题目 输入数字 n,按顺序打印出从 1 到最大的 n 位十进制数. ...
- 用CALayer实现下载进度条控件
用CALayer实现下载进度条 效果: 源码: // // ViewController.m // ProgressView // // Created by YouXianMing on 14/11 ...
- Android开发(7)数据库和Content Provider
问题聚焦: 思想:应用程序数据的共享 对数据库的访问仅限于创建它的应用程序,但是事情不是绝对的 Content Provider提供了一个标准的接口,可供其他应用程序访问和使用其他程序的数据 下面我们 ...
- 未能从程序集 C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Data.Entity.Build.Tasks.dll 加载任务“EntityClean”
问题: 未能从程序集 C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Data.Entity.Build.Tasks.dll 加载任务“Entity ...
- layer 遮罩层等待
效果 代码: js函数之前:var msg = layer.msg('努力中加载中...', {icon: 16,shade: [0.5, '#f5f5f5'],scrollbar: false,of ...