Coding-Standard .Net

 

  1. Please do code cleanup / indentation before committing your changes to version control (GitHub), we can use VS default code cleanup (part 1 and 2) or VS Code Prettier as well.

Why? Answer: because its showing so many files difference when we do cleanup and indent and then try to commit.


** This will apply to both front-end and back-end.

------------------------------------------------------------------------------------------------------------------------------------------

  1. Please don’t write any business logic inside controller, | why?  Answer: because we want to use same method (business logic) in different places.

we need to write only those code, we are fetching customerId / phoneNumber / providerIdentificationId or any of the JWT token data inside controllers. – any other code, which is actually our business logic, we can add that inside method of service or repository.

Please find below screenshot for reference

------------------------------------------------------------------------------------------------------------------------------------------

  1. There is no need to add try catch block multiple times, example as below.

Attached 2 images for your reference

1st one is method written in controller, and next one is method written inside AccountBLService. We have already written try catch block inside AccountBLService, then there is no need to add try catch block inside controller.


------------------------------------------------------------------------------------------------------------------------------------------

  1. There is no need to add logger in controller (only when we are fetching data from JWT token (HTTPContext)

Why? Answer: Now if you see Point 3, mentioned above, we understood that, CreateAccount method can be used in multiple places (similarly, we have so many methods / files in Common Lib, we are using across multiple repositories). So, if we add logger inside that method, then we can say, we have added logger across multiple repo and no need to write same inside controller.


------------------------------------------------------------------------------------------------------------------------------------------

  1. Please do proper naming convention to your class names and properties.

Normally in C# we use Pascal case, and when it responds back to postman / FE, it will automatically convert back to camel Case (Front-end we normally use camel Case)


https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions


** There are some case, example: socket response, where we manually need to convert to camel case and then respond.


Example: we have many classes with name like BB_ **, if you see, in class name there is no need of _

Example: we have many class properties with camel Case, we need to make it Pascal case.


Example: We see, many classes have like this, 

siteId, SiteID, SiteId ------------ better make it to SiteId (C#) and siteId (Front-end JavaScript)


------------------------------------------------------------------------------------------------------------------------------------------

  1. Please give proper naming convention of the class based on its functionalities, 

Example: I see, normally we are using everywhere class name ending with Model or BO.


My question is, using this, we are not able to understand if that is request class or response class.


For example: have a look on below,

Using this naming convention, we are able to understand, if its request or response class, as well as what business logic it will try to do as well. (in this case its EndRound request)



Another example below.


Earlier, I have tried to convert request class, and make it as below 

“Get”, “BetSlipStatusList”, “Request” --- I have added “Ump” only because its not actually “Ump Library” (which we can assume third party provider.


------------------------------------------------------------------------------------------------------------------------------------------

  1. There is no need to write FromBody keyword inside controller. .Net system will automatically assume its from Body only, Its required only in case of FromQuery


------------------------------------------------------------------------------------------------------------------------------------------

  1. I see in function / method name, while passing parameters, we are giving different name.

Its better if we follow same in all the case, for example: sometimes its written model / req / request / oRequest ------ make it unique / same across all the methods like “oRequest”



Comments

Popular Posts