简体   繁体   中英

private WCF service constructor

I know for a fact that the static constructor of a WCF service will be shared for all users, how about the private constructor? is it per user?

public partial class MyWCF : IMyWCF
{
    static MyWC()
    {
        // caching stuff here, used by all users
    }

    private MyWC()
    {
       // is it per user?
    }
}

It depends if you only have a single instance of MyWCF. You probably don't, so the answer is probably not.

If you would have a single instance you would had this attribute on top of your service:

[ServiceBehaviour(InstanceContextMode=InstanceContextMode.Single)]
public partial class MyWCF : IMyWCF
{
}

In fact, it doesn't matter at all if it's private or not. That only control who can instantiate it.

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