Last post Jul 28, 2014 04:06 AM by PatriceSc
Jul 26, 2014 03:51 AM|dotnetterAMG123|LINK
Jul 26, 2014 06:23 AM|PatriceSc|LINK
"generic" requirements is problematic ;-) "versatile" seems also a clue about unclear requirements. What if you focus first on those "scenarios" you want to support ?
Jul 26, 2014 01:41 PM|dotnetterAMG123|LINK
Jul 26, 2014 03:35 PM|PatriceSc|LINK
This is the usual Lazy<T> based implementation and it's perfectly fine with me.
For the scenario, what if you need a user session or http request scoped singleton ? Is this is a scenario you would like to support as well ?
Jul 26, 2014 03:46 PM|dotnetterAMG123|LINK
Jul 26, 2014 05:19 PM|PatriceSc|LINK
So as it fit your needs, just go for it ?
Jul 26, 2014 07:40 PM|dotnetterAMG123|LINK
Jul 27, 2014 08:27 AM|PatriceSc|LINK
Stricly speaking it could be still misused (ie if called zillion of times or if you introduce a side effect in your singleton creation, using Lazy rather than an immediate creation could make a difference our could be misused if the scope of the singleton
is not correct (for example beginners using static for user data in a web app)) but it is very unlilely you'll ever run into this..
So basically yes this implementation does work fine and go for it if I'm just looking at this regardless of any other consideration such as what does the singleton exactly.
Actually I shouldn't have started to answer ;-). Unfortunately I'm quite picky - so stricly speaking I can't tell you that whatever you are doing it will always work and will fit your needs. At the same time I'm quite pragmatic ie when you have done your
"best effort", to me it's best to move away and possibly spend a little effort to fix an actual issue you'll run into rather than investing too much effort in questioning your design again and again for all kind of rare events most of them you'll never run
into or even just can't think about before seeing them to happen.
For example every time you create a guid, you have a non 0 likelyness to create a duplicate. Still most dev don't handle this scenario and me neither. Still I saw once someone who did this "just in case".
Jul 28, 2014 12:48 AM|dotnetterAMG123|LINK
Jul 28, 2014 04:06 AM|PatriceSc|LINK
Yes, this is the default for Lazy<T>.