All Questions
Tagged with programming-practices c#
90 questions
0
votes
4
answers
224
views
Use-cases for Expression<TDelegate> except translating to another language?
So I just learned about Expression<TDelegate>. As a library author this really intrigued me; my libraries make extensive use of source generators to generate both high-performance code and code ...
-2
votes
1
answer
163
views
Best Practices for Managing Multiple Entity Types in ASP.NET Core
I'm working on an ASP.NET Core application that requires handling multiple types of a single entity. Each type has its own properties and validation rules, which has led to confusion and complexity in ...
0
votes
3
answers
232
views
Use of environment variable or appsettings as a counter, good or bad practice [closed]
I'm wondering if it's bad practice to have a variable in a webserver which counts the amount of incoming requests and put it in an environment variable.
In C# for example you have System.Configuration....
0
votes
1
answer
370
views
How best to share common steps between services while allowing them to provide their own behaviour
I've started working on a C# codebase. There are three services which run the same set of steps of three kinds of objects, each returning IResult:
public IResult FooService(Foo foo) { ... }
public ...
-1
votes
3
answers
873
views
Would Injecting dependencies in C# as default parameters be a bad practice?
Given the (old) debate over whether Singletons are overused/abused/are worth it - would it be a bad idea to inject the dependencies as default parameters? In this way, we could get rid of defining ...
2
votes
3
answers
470
views
C# Duplicated usage of an if/else condition and a ternary operator. A good practice?
I had a debate with a work mate regarding the following code as to which one of it would be the better practice:
My code (in pseudo):
var A = <precondition either TRUE or FALSE>;
var B;
if(A)
{
...
-2
votes
2
answers
3k
views
Best practices around writing testable extension methods
I’m currently working in C# and I’d like to write and extension method against a type. There is a small amount of repeated logic between classes surrounding JSON deserialization, using the ...
9
votes
7
answers
4k
views
what can go wrong in context of functional programming if my object is mutable?
I can see the benefits of mutable vs immutable objects like immutable objects take away lot of hard to troubleshoot issues in multi threaded programming due to shared and writeable state. On the ...
1
vote
2
answers
3k
views
One API or Two APIs one for internal use and the other for external use
I follow the Layered architecture Like this:
But with two differences:
I use Blazor Assembly for UI Layer.
I have API layer(REST) In between the presentation layer and the service layer.
My ...
1
vote
2
answers
113
views
Using public nested types to self contain complex POCOs for serialization
So a lot of the web says not to use public nested types unless you need the member visibility semantics (including this msdn article, even though that article hasn't been touched since 2008).
For the ...
50
votes
5
answers
62k
views
When and why to use Nested Classes?
Using Object Oriented Programming we have the power to create a class inside a class (a nested class), but I have never created a nested class in my 4 years of coding experience.
What are nested ...
1
vote
0
answers
60
views
How to implement timing-mechanism for fantasy draft process utilizing ASP.NET Core 3.1 SignalR
I have developed a Fantasy Draft system utilizing ASP.NET Core SignalR, along with Azure's SignalR service (for backplane/scaling stuff).
Last year I utilized a poor-mans' javascript version that just ...
-1
votes
1
answer
8k
views
What is meant by service? [closed]
We know there are services in windows but I am reading a book by Ed Snider and he uses the term “service” whenever his program requires a certain feature/functionality.
Like he creates a navigation ...
40
votes
6
answers
38k
views
Try/Catch/Log/Rethrow - Is Anti Pattern?
I can see several post where importance of handling exception at central location or at process boundary been emphasized as a good practice rather than littering every code block around try/catch. I ...
10
votes
2
answers
2k
views
What is the name for the integer part of a enum?
I've been writing some code comments, and I've been trying to refer to the index integer of a enum type, but I'm not sure what it's called. I'm tempted to call it the identifier, however there is ...