We are experiencing differences between a service running on .net core and .net framework.
We’re currently using SS 5.1.0 and .net core version 2.1.300.
When we register a WebServices
G.IOC.Register(c => new Service0()).ReusedWithin(ReuseScope.Container);
When running on .net core on windows 10
The service Service0 is recreated on every call to the web-service regardless of the value of ReusedWithin setting
The public instance variables are set to null before the destructor is called. Private instance variables are unchanged. Note: Our code is not setting the public values to null.
Notes: In our example there are two other services that are being started after this. At one point this worked, and we don’t know what has changed to affect it.
Do you have any techniques to help us troubleshoot this?
Again, the .NET Framework running on windows 10 version works correctly.
Container is the same as singleton as there’s only 1 container in ServiceStack’s Funq. You can use None to register a transient dependency or Request for a per-request dependency for HTTP Requests.
I’m not sure what you mean by registering Web Services, but ServiceStack Services need to be registered as transient, i.e. ReuseScope.None.
I think the difference between .net core and .net framekwork is as follows:
.net framework saw our public variables and knew they were set as Registered in the IOC but not RegisterAutoWired. And they were left alone.
But
.net core saw our public variables, and did not check if they were Registered in the IOC but assumed they were RegisterAutoWired and set them to null as no value was set for the RegisterAutoWired for that object.
Just use ReuseScope.None so it’s consistent like every other ServiceStack Service. Request scope only works in the context of a HTTP Request. There is still only 1 instance of the Service created per request so Request scope isn’t giving you anything except incompatibility issues when trying to use your Service outside a HTTP Request.