We use abp in a really product for user. And there is api, it's so easy, but the response time for it is about 1 second. We think it shouldn't be, then we investigate it, found the execution time for the application service method is about 100 ms, and resolve the application service spent about 1 second.
We use IocManager.RegisterAssemblyByConvention(thisAssembly) for register.
Following screenshot is from the log file for investigation:
My questions are:
Before, we use default DependencyLifeStyle as Transient, and we make some changes to set DependencyLifeStyle to per request. And the resolve is so fast now.
The code changes as below:
public override void PreInitialize()
{
IocManager.IocContainer.Kernel.ComponentRegistered += Kernel_ComponentRegistered;
}
private void Kernel_ComponentRegistered(string key, IHandler handler)
{
foreach (var interceptor in interceptors)
{
if (interceptor.Key.IsAssignableFrom(handler.ComponentModel.Implementation))
{
handler.ComponentModel.Interceptors.Add(new InterceptorReference(interceptor.Value));
}
}
if (handler.ComponentModel.Implementation.Assembly.FullName.Contains(".Domain"))
{
if (handler.ComponentModel.LifestyleType == LifestyleType.Transient)
{
IocManager.IocContainer.Register(
Component
.For(handler.ComponentModel.Implementation)
.ImplementedBy(handler.ComponentModel.Implementation)
.LifestyleCustom<MsScopedLifestyleManager>()
.IsDefault()
.Named($"{key}-1")
);
}
}
}