Resolving Autofac components in background Tasks in ASP.NET

前端 未结 2 882
执笔经年
执笔经年 2020-12-19 10:20

Using Autofac in ASP.NET along with the ContainerDisposalModule, how can i support fire and forget calls that have component dependencies that need to be resolved? The prob

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-19 10:45

    You need to create a new lifetime scope that is independent of the request lifetime scope. The blog post below shows an example of how to do this using MVC but the same concept can be applied to WebForms.

    http://aboutcode.net/2010/11/01/start-background-tasks-from-mvc-actions-using-autofac.html

    If you need to ensure that the async work is definitely performed after the request is finished then this is not a good approach. In such cases I would recommend posting a message onto a queue during the request allowing a separate process to pick it up and perform the work.

提交回复
热议问题