Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

ISingletonDependency does not create singleton instances #482


User avatar
0
ofir1234 created

Hi. I have the following class signatures :

public interface IConfigurationManager : IApplicationService {...}
public class ConfigurationManager : IConfigurationManager, ISingletonDependency {...}

I also have this controller in the WebApi project :

public class TrendsController: AbpApiController

And it has a constructor which receives an IConfigurationManager argument.

What I've noticed is that for every api request from TrendsController, The ConfigurationManager class is recreated. But I wanted a single instance for the whole project runtime (therefore I use ISingletonDependency, as written in the documentation here: <a class="postlink" href="http://aspnetboilerplate.com/Pages/Documents/Dependency-Injection">http://aspnetboilerplate.com/Pages/Docu ... -Injection</a>). I know that because I placed a Logger.info call inside the ConfigurationManager constructor, and I see it's recreated for every api call.

Can you please tell me what have I missed ?

Thanks.


1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    IApplicationService inherits ITransientDependency. So, your class will be transient. Why you implement IApplicationService? Your ConfigurationManager is not an application service. Just don't implement IApplicationService, your code will work.