Giter VIP home page Giter VIP logo

Comments (13)

yang-xiaodong avatar yang-xiaodong commented on July 21, 2024

你使用最新的 2.0.1-preview-21392243 版本,看是否还有此问题?

from cap.

kulend avatar kulend commented on July 21, 2024

还是有问题。
_20170908103345
这里需要实例化controller,但貌似已经不在一个请求的生命周期内了。

from cap.

yang-xiaodong avatar yang-xiaodong commented on July 21, 2024

Controller 和 CAP Subscribe 的调用是不在一个生命周期的

from cap.

yang-xiaodong avatar yang-xiaodong commented on July 21, 2024

你贴一下你的代码,我怎么样才能复现你的问题?

from cap.

kulend avatar kulend commented on July 21, 2024

发现问题所在了,controller的构造函数是这样的
private IUserActionLogService service; public LogController(IUserActionLogService service) { this.service = service; }
注册service是InstancePerLifetimeScope
builder.RegisterAssemblyTypes(typeof(IUserService).GetTypeInfo().Assembly) .Where(t => t.Name.EndsWith("Service", StringComparison.CurrentCultureIgnoreCase)) .AsImplementedInterfaces() .InstancePerLifetimeScope();
这样IUserActionLogService就没法实例化,然后就报上面的错了。
不知道大神有没有好的解决办法?

from cap.

kulend avatar kulend commented on July 21, 2024

使用ICapSubscribe Service也有同样的问题,这个问题希望能解决下,总不可能Subscribe用到的都必须注册成Singleton或是Transient吧?

from cap.

yang-xiaodong avatar yang-xiaodong commented on July 21, 2024

Scope的是没有问题的,你用的Autofac?

from cap.

kulend avatar kulend commented on July 21, 2024

@yuleyule66

是的,用的是Autofac

from cap.

yang-xiaodong avatar yang-xiaodong commented on July 21, 2024

没有测试过Autofac,CAP内部拿Services都是微软的DI的,建议切换为微软DI

from cap.

kulend avatar kulend commented on July 21, 2024

亲测真和autofac有关系,那这个是autofac的锅?

from cap.

kulend avatar kulend commented on July 21, 2024

@yuleyule66
我调试了cap的代码,貌似是有点问题。
在\src\DotNetCore.CAP\IQueueExecutor.Subscibe.cs第107行:
await _consumerInvokerFactory.CreateInvoker(consumerContext).InvokeAsync();
CreateInvoker里面,using (var scope = _serviceProvider.CreateScope()),但返回了才去InvokeAsync,那这个scope已dispose掉了吧。Invoke会去实例化controller,然后就报错了。
这个地方我把InvokeAsync移到using里面测试就正常了。
public async Task CreateInvokerAndInvokeAsync(ConsumerContext consumerContext)
{
using (var scope = _serviceProvider.CreateScope())
{
var context = new ConsumerInvokerContext(consumerContext)
{
Result = new DefaultConsumerInvoker(_logger, scope.ServiceProvider, _modelBinderFactory, consumerContext)
};
await context.Result.InvokeAsync();
}
}

from cap.

yang-xiaodong avatar yang-xiaodong commented on July 21, 2024

这里看起来好像有问题,但是我这边复现不到呢? 你是怎么测试出来的呢?

from cap.

yang-xiaodong avatar yang-xiaodong commented on July 21, 2024

@kulend 升级 2.0.1-preview-21993007 再看一下有没有问题呢

from cap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.