[英]How to have a PerWebRequest Lifestyle in all my transient dependencies using ABP?
We're facing an issue in terms of performance in a .NET Framework 4.6.1 application that uses ABP 4.8.1. 就使用ABP 4.8.1的.NET Framework 4.6.1应用程序的性能而言,我们面临一个问题。 The detected issue is related to a continuous use of the dependency injector resolver with transient dependencies. 检测到的问题与具有临时依赖关系的依赖关系注入程序解析器的持续使用有关。
We were trying to change the "Lifestyle" from Transient to PerWebRequest, using Castle Windsor (This is the default package that ABP uses) but if we do this we keep getting this exception: 我们试图使用Castle Windsor(这是ABP使用的默认软件包)将“生活方式”从Transient更改为PerWebRequest(这是ABP使用的默认程序包),但是如果这样做,我们将不断收到此异常:
Looks like you forgot to register the http module Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule”? 您似乎忘记了注册http模块Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule”?
Of course we added the necessary lines, as mentioned in: https://stackoverflow.com/a/34920667/12042620 当然,我们添加了必要的行,如在https://stackoverflow.com/a/34920667/12042620中所述
The exception was thrown when we tried with a proof of concept like this: 当我们尝试使用这样的概念证明时,抛出了异常:
public class MyModule : AbpModule
{
public override void PreInitialize()
{
Database.SetInitializer(new CreateDatabaseIfNotExists<MyDbContext>());
Configuration.DefaultNameOrConnectionString = "Default";
}
public override void Initialize()
{
IocManager.IocContainer.Register(
Component
.For<MyDbContext>()
.LifestylePerWebRequest()
);
IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
}
}
I was trying to find some other possible solutions but all of them are related to .NET Core (they use 'Scoped' instead of this). 我试图找到其他可能的解决方案,但所有这些解决方案都与.NET Core有关(它们使用'Scoped'代替了它)。 Is there any way to implement this Lifestyle for all our dependencies while using ABP? 在使用ABP时,有什么方法可以为我们所有的依赖关系实现这种生活方式吗?
Try to register your types with LifestylePerWebRequest
as seen here https://github.com/aspnetboilerplate/aspnetboilerplate/blob/e0ded5d8702f389aa1f5947d3446f16aec845287/src/Abp.Web.Mvc/Web/Mvc/Controllers/ControllerConventionalRegistrar.cs#L11 尝试使用LifestylePerWebRequest
注册您的类型,如此处所示https://github.com/aspnetboilerplate/aspnetboilerplate/blob/e0ded5d8702f389aa1f5947d3446f16aec845287/src/Abp.Web.Mvc/Web/Mvc/Controllers/ControllerConventionalRegistrar.cs#L11
And add this registrar to the PreInitialize of your module like here https://github.com/aspnetboilerplate/aspnetboilerplate/blob/e0ded5d8702f389aa1f5947d3446f16aec845287/src/Abp.Web.Mvc/Web/Mvc/AbpWebMvcModule.cs#L29 并将此注册器添加到模块的PreInitialize,例如此处https://github.com/aspnetboilerplate/aspnetboilerplate/blob/e0ded5d8702f389aa1f5947d3446f16aec845287/src/Abp.Web.Mvc/Web/Mvc/AbpWebMvcModule.cs#L29
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.