Replies: 1 comment 3 replies
-
Can I answer it depends, and leave it at that? 😉 I think I'd go with Transient in almost all scenarios. There is a theoretical risk with Scoped that there could be some form of multithreaded access and that might not be guaranteed to work (although in practice both the chance of multithreaded access, and the chance of a bug are both very small in most scenarios.) I don't really see much of a benefit to using Scoped, so I probably wouldn't. The only benefit there might be in using Scoped is less work for the garbage collector, so that's the "it depends" bit. If you already know that garbage collection will cause you an issue, then Scoped might help alleviate that in certain circumstances. In reality, what seems to give the garbage collector more of a problem is long-lived instances of reference types. The longer an item exists on the heap, the larger the generation number it gets assigned, and as I understand it, Gen 2 collection is very expensive. Using a lifetime of Scoped is likely to result in instances existing for longer, so you'd have to do a test of your particular scenario to work out if there really is a benefit to Scoped and not just go on an assumption. So, Transient. Almost always (but not quite always.) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Maybe this is a dumb question, but I find myself wondering how y'all will be registering your factory classes in Csla 6 (the factories that allow us to get rid of static constructors in business objects). Would you register this factory as scoped or transient?
and it's base class for reference
Beta Was this translation helpful? Give feedback.
All reactions