简体   繁体   中英

.net static object lifecycle

I've got a DAL library with a repository static class; it's initialized via singleton pattern (static constructor). There is website that uses this DAL library, and a windows service project in the same solution.

As far as know, there would be two instances of the singleton object, one in each domain of site and WINservice. Is that right?

For the web site app, after some idle time, the domain in unloaded, and so the repo class will be unloaded too, right?

And last question about the winservice: as far as know this domain will never be unloaded, while the service is running, so that the repo object will remain in memory?

PS: What would happen, if I create a subclass object, eg worker for winservice, which will use the repo class inside of it.

using (var worker = new worker())
{
    //some DAL manipulations
}

Would the repo object be destroyed once I leave the worker context?

Thanks for any help.

As far as know, there would be two instances of the singleton object, one in each domain of site and WINservice. Is that right?

Yes

For the web site app, after some idle time, the domain in unloaded, and so the repo class will be unloaded too, right?

Yes (the rules for recycling the app pool can be setup in IIS)

And last question about the winservice: as far as know this domain will never be unloaded, while the service is running, so that the repo object will remain in memory?

Yes

Would the repo object be destroyed once I leave the worker context?

No (unless you dispose of it of course)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM