salty_pepper
What's the difference between webhook and sending an HTTP request to an endpoint exposed by client
Hi I'm learning about building web api at the moment. Came across this concept called webhook and is now confused.
What's the difference between webhook and sending an HTTP request to an endpoint exposed by client?
Theoretically I can keep a list of client endpoints and their interested events in the databse. When an event happens (eg. placing down an order), I can just send a HTTP request to all the clients that subscribe to this event. Why on earth do I need a webhook?
8 replies
What do use in a multi-threaded environment?Dictionary with lock OR ConcurrentDictionary?
Doesn't Dictionary with lock make ConcurrentDictionary redundant?
As far as I understand to make dictionary thread safety we can just use lock to make sure other threads don't have access to the dictionary, why use ConcurrentDictionary ?
6 replies
Reference type variables themselves are stored on the stack, is that correct?
While we often say value types live on the stack, ref types live on the heap.
That's not completely true right?
1. eg. Building house = new Building();
In this case, house is simply a pointer to the building object. And it's stored on the stack. While actual building object is stored on the heap.
2. When we assign int to a List<int>, those int values actually live on the heap. ( Of course if we create int variables directly, they are stored on the stack)
Is this the correct interpretation?
10 replies
✅ How is aggregate in DDD related to event sourcing and CQRS?
I'm confused about the use of aggregate in a system with event sourcing and CQRS.
As far as I understand, CQRS write model emits domain events to the event store. Adding a domain event to the event store triggers a projection, which updates the CQRS read model.
Where does aggregate come in?
20 replies
Who handles dependency Injection in a class library?
Suppose there is a class library
TestService
which requires some dependencies.
Whose responsibility would it be to handle it?
1. Let caller handle DI. This means caller will need to know about the underlying classes in the class library to be able to come up with the dependencies and use it. Seems a bit cumbersome? Like new TestService(dep1, dep2...), where deps could be interfaces defined in the class library
2. Providing default implementation in the class library ( maybe in constructor? ), so if dependencies are not passed in when creating the service, we create default concrete classes within the class library constructor and use them instead.
// make parameters optional, and create actual deps inside the constructor
TestService(null, null)
3. Other ways?61 replies
Are we supposed to test factory pattern in unit test?
Suppose we have some code that does something, during the execution it calls the factory class to create an instance depending on some property.
Do we just mock the factory class in unit test? Or should we test whether the factory class is returning the right type of object?
11 replies
✅ Looking for experienced dev to do a quick live code review
Hello, is there any experienced dev here interested in doing a live code review with me to review my very small dot net project assignment?
It's a tiny project with only a few files, can be done in 15 min I reckon.
We can do it via discord chat?
10 replies
Open Closed Principle confusion
In the case of some logic involving a class. Eg. There maybe an Account class and we calculate the interest differently depending on the type of account with if else. ( eg. if Regular calc this way, else Saving calc that way) . This is undesirable.
With Open Closed Principle, we were taught to turn the original class ( Account ) into an interface, and then introduce derived classes which have their own versions of calcInterest . Now that calcInterest method is implemented in derived classes, we don't need to update existing code logic to accomodate for any new Account type everytime we introduce a new derived Account class.
However, my question is that, when we create the derived class. Wouldn't there still be if else loop to determine which type of derived class we consturct, doesn't that go against open closed principle?
13 replies