« first day (4050 days earlier)      last day (900 days later) » 

4:00 PM
if you have static or constant state, it should probably be private to the class that uses it
 
mr5
indeed
you can assume wiet is mad when he stops talking
 
or just taking a shit
it takes a lot to get me mad
havent been mad in about 6 years now
 
mr5
what was the last time you get mad about?
 
and the last time I was mad, there was a buildup of approximately 4 months
 
mr5
like a true saiyan
 
4:02 PM
[Captain Obvious] static would be better
 
last time I was mad, I was mad at 2 people being mad at each other and not realizing how they affected everyone around them
ok, now I am mad
@CaptainObvious NO
 
@Wietlol what is the difference between 2 & 3?
 
a singleton class vs a normal class that you reuse?
 
[Captain Obvious] service provider is either newing it up every time or using a singleton anyway
[Captain Obvious] singletons aren't thread safe
 
singletons are thread safe
unless you have no clue how to write one
 
4:04 PM
[Captain Obvious] (well, they might be but any properties aren't guaranteed to be)
 
in that case, neither are static fields
 
@Wietlol yes, AddSingleton to store state, and reuse every where
 
[Captain Obvious] I mean yeah definitely storing state like that isn't wise
 
a normal data class that you inject into your serviceprovider still has a lifecycle
 
[Captain Obvious] If you're gonna do that you may as well use the built in asp state thing (assuming asp)
 
4:05 PM
a singleton class, aka a class with a private constructor and only one static property that exposes only one instance, is retained for the entirety of your application's runtime
 
[Captain Obvious] what no
 
ok
 
[Captain Obvious] that's not what a singleton is
[Captain Obvious] That's just kinda static but harder
 
that is what a singleton is
public class MySingleton
{
    private static Object Lock { get; }
    private static MySingleton Instance { get; set; }
    public static MySingleton GetInstance()
    {
        if (Instance == null)
            lock (Lock)
                if (Instance == null)
                    Instance = new MySingleton();
        return Instance;
    }

    private MySingleton() {}

    public void Poop()
    {
        Console.WriteLine("BRRRRRRT");
    }
}
 
mr5
I see. You're not a real C# fan
 
4:14 PM
why?
because I use Object?
because I use properties instead of fields?
because I BRRRRRT?
 
mr5
yeah, it should just be "C#"
Poop(); Poop();
// C# C#
:D
most of the time, you don't actually need to implement lazy singleton though
 
perhaps you could indeed do public static MySingleton Instance { get; } = new MySingleton();
however!
that assumes that the static initialization is thread safe
which is something I cannot guarantee
although, the lock object should've been private static Object Lock { get; } = new Object();
forgot to initialize that
199
A: Is the C# static constructor thread safe?

ZoobaStatic constructors are guaranteed to be run only once per application domain, before any instances of a class are created or any static members are accessed. https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-constructors The implementation shown is thre...

ah, it is thread safe
I suppose it would have to be, otherwise the lock object would also not really work
no
 
mr5
that's dumb :D
 
I am saying that dotnet loads your classes lazily
or at least your dlls
 
mr5
what time is it there?
my brain is deteriorating
 
4:22 PM
imagine you have 2 dlls
myapplication.dll
mylibrary.dll
application uses a function from library
but before that function is invoked, application could do a lot of other stuff
 
mr5
yeah, I could see that.
 
and only when that library function is invoked, then dotnet loads the dll and does the static initialization
it might even do the static initialization on class level, like Java does, but I am not sure
I am 100% sure that it can do it on dll level
and I am 100% sure that I fixed an error today that wouldve been solved ages ago if it didnt
 
XD
> Implementing the Singleton Pattern in C#
> Unfortunately, there are four downsides to the pattern:
> 1. It doesn't work in Java.
some people need to have a brain surgery
 
mr5
I want to reference a quote but I forgot the first part:
> blablabla is full of tradeoff/compromise
@Wietlol that's a me
 
4:28 PM
the fifth version is interesting though
and it does assume that dotnet loads classes lazily on class level
and I assume we can assume that the article is correct
 
mr5
@Wietlol you turn it upside down by cutting the context. you <insert description here which I forgot due to my deteriorating brain>
 
yes, they are aware that it is an odd thing to comment on, but still
 
mr5
why are you referring to him as they
 
> how to do this in C#
well, it doesnt work in Javascript, and we all know that if you write front end in C#, you most likely also do Javascript as well
 
mr5
it's true though. I came from Java then C#
a lot of devs probably
 
4:31 PM
@mr5 I dont know who wrote it, or how many wrote it, or what sex the person was that wrote it
 
mr5
Jon Skeet wrote it
 
ah, the apache helicopter then
 
mr5
:D
hey, wiet. don't be mad okay?
I need to sleep now. byeee!!!!
 
bai
 
[Captain Obvious] the system works lads
 
5:15 PM
Lori Colston on November 17, 2021
We’re thrilled to announce a new and foundational feature, Content Health, that helps to intelligently identify and surface potentially outdated or inaccurate knowledge—content that needs to change.
 
 
1 hour later…
G K
6:31 PM
Hi all
I have an event handler in my TestCode. I need to check something and need to do assert.
I am using Assert.Fail, but this Assert.Fail method is throwing an exception which is propogating to the caller.
But my goal is to fail my test.
do I have any other options to fail my test?
and it does not fail my test since the exception is propogating to the actual caller code.
there I am just logging and doing nothing in the caller catch block.
What else can I do for these scenario's?
 
I assume your code looks something like
event.Register(() => Assert.Fail());
event.Execute();
and Execute itself catches the exception?
generally speaking, you'd have to keep track of it's invokes
28
A: Verify a method is called or not in Unit Test

dcastroLicenseManagerService.Verify(m => m.LoadProductLicenses(),Times.Once); By calling the LicenseManagerService property, you're creating a new mock object. Naturally, no invocations have ever been performed on this instance. You should change this property's implementation to return the same inst...

iirc, it was called a "spy" but I havent touched unit testing domain in quite a while
in simple terms, you basically test this
var numberOfTimesCalled = 0;
event.Register(() => numberOfTimesCalled++);
event.Execute();
Assert.Equal(0, numberOfTimesCalled);
however, the verify approach is much cleaner
 
G K
7:42 PM
No, it does not work in my case.
My code/utility is based on N-unit framework which actually does some impl. on the actual code and then have assertion statements.
So just checking if a method is called does not solve the problem.
 
can you show what you are trying to do?
 

« first day (4050 days earlier)      last day (900 days later) »