Skip to main content
14 votes
Accepted

ASP.NET REST controller with try-catch error handling

throw ex; This is a fatal mistake. It'll create a new stack-trace and you won't be able to tell where the actual exception occured. If you want to rethrow it then ...
t3chb0t's user avatar
  • 44.7k
13 votes

C# Am I using proper SOLID principles?

I suppose the simplest thing is to go through the principles: SRP - Cannot see any 'too big' things in your example OCP - The example is small enough and you are not using class inheritance that I ...
Jamie Stevenson's user avatar
6 votes

C# Am I using proper SOLID principles?

IMO returning IEnumerable<T> from an API is a violation of "L", as running GetEnumerator() a second time (or ...
David Browne - Microsoft's user avatar
5 votes

Custom HttpClient implementation for third part usage with sync/async calls

internal class Client : IDisposable { private static HttpClient _client; private static Uri _baseAddress; Neither of those fields should be ...
Peter Taylor's user avatar
  • 24.5k
5 votes

ASP.NET REST controller with try-catch error handling

Typically in an ASP.NET app (and in fact in any app), you should only catch and handle the base System.Exception in a single place as close to the application entry ...
Matt Cole's user avatar
  • 968
4 votes
Accepted

Trying to map JSON to different classes in web API

The first thing to do is to remove duplicated code. If you do not need further processing DeserializeObject<T>() returns T ...
Adriano Repetti's user avatar
4 votes

Method GetById and SingleResult

[EnableQuery] and SingleResult does in fact return 404 OOTB, that is one of the key reasons for ...
Chris Schaller's user avatar
4 votes
Accepted

Setting up pagination links inside a WebAPI Controller

The intention When I have all matching objects - I pass them to a "Paging" method within the service (I think I have to do this in the service rather than the repository because a generic repo ...
Flater's user avatar
  • 5,720
4 votes
Accepted

IsDatabaseUp returns true or throws exception

The naming convention Is… implies that the function is a predicate, returning either true or false. If you wanted to throw an exception when the database is down, ...
200_success's user avatar
4 votes
Accepted

Reading MultiPart From Data with descriptors

The naming and variable conventions in your method look like it was written by at least three different persons: ...
t3chb0t's user avatar
  • 44.7k
4 votes

ASP.NET REST controller with try-catch error handling

The linked post adds a neat summary: So, to sum up: Don’t catch fatal exceptions; nothing you can do about them anyway, and trying to generally makes it worse. Fix your code so that it ...
Flater's user avatar
  • 5,720
4 votes

Subscribe to Event form one service to another

in your case I would try to avoid subscribing to events as this couples the projects and references and prevents the garbage collector to clean up the unused service. if you are creating new services ...
Mightee's user avatar
  • 141
4 votes
Accepted

ASP.NET Web API for currency

GetCurrencies I would suggest to create a named/typed HttpClient with the proxy handler to make it reusable In this SO topic ...
Peter Csala's user avatar
  • 10.8k
4 votes
Accepted

Abstraction Layers and Best Practices in Authentication with EF Core

Do you recommend adding a layer of abstraction on top of ef core for example we have an API controller responsible for authentication do I just call ef core methods directly in the controller or do I ...
Peter Csala's user avatar
  • 10.8k
3 votes
Accepted

ASP.NET Web API Authentication For Xamarin App

It is fine to refresh the token on every app start. It will also prevent potential hijacked tokens to be usefull for a longer time, when the token is refreshed everytime the user starts the app and ...
Martin C's user avatar
  • 140
3 votes
Accepted

Handling external API calls status code in my application

I have only 2 things to note. Returning the same status code as the remote server could lead to confused clients of your API due to incorrect status codes. What if the remote server has returns a 5xx ...
MindSwipe's user avatar
  • 235
3 votes

Calling rest API with HTTPWebRequest

Looking at the code I would try to, make the code a bit more robust. Experiences has thought me that a perfectly good working web service sometimes fails or times-out. To capture this you can update ...
Walter Vehoeven's user avatar
3 votes
Accepted

Subscribe to Event form one service to another

in your UnsubscribeUser Method, I wouldn't worry about checking to see whether or not the user is actually subscribed or not, if this method is called I would ...
Malachi's user avatar
  • 29.1k
3 votes
Accepted

Exception, errors handling, best practice in WebApi Core

Exceptions are pretty costly so as a general rule of thumb they should be avoided. Especially when we talk about REST endpoint where response time is crucial. Also, to my taste you're messing up ...
Bohdan Stupak's user avatar
3 votes

Parallel Calls to External WCF Service - ASP.NET Web Api

I think instead of creating an unknown amount of task using PLinq would make it simpler and have control over the number of task inflight/created something like ...
CharlesNRice's user avatar
  • 4,438
3 votes
Accepted

Export and import work items from Azure DevOps

Url handling Rather than recreating some URLs over and over again you can define them only once and use them multiple times: ...
Peter Csala's user avatar
  • 10.8k
3 votes

Concurrent Requests Handling in ASP.NET Web API 2

Code does not follow the following best practices : Naming convention (properties should be PascalCased). Method should have a single responsibility. Multiple ...
iSR5's user avatar
  • 6,383
3 votes

Seeking Suggestions for Improving My Program.cs File for a .NET Project

Comments Try to avoid commenting the what and the how This is just basically echos the code itself Try to capture the why and why not decisions This preserves context, why option A has been chosen ...
Peter Csala's user avatar
  • 10.8k
2 votes

Controller with too many parameters with DI

Create a class that will expose the services as properties. That class should also have DI set up. Register that class with interface in the container. Inject the class into your own controller.
Marko's user avatar
  • 21
2 votes

C# - Entity Framework + Repository pattern + Unit of work pattern

I understand how you don't like to have a reference to the repository interfaces in your uow. I could argue against it :), but I won't :) I'm not sure about Ninject, I've been using Autofac for a ...
Akos Nagy's user avatar
  • 121
2 votes

Download file uisng ASP.Net WebApi

There can be two improvements in above code block initially as below: Method should be async, this will help your application in terms of performance for parallel requests In order to delete the ...
KALPESH BADGUJAR's user avatar
2 votes
Accepted

Giving error response in Web API

Handling exceptions within the action is a cross-cutting concern that can be extracted and placed into one of the available extensiblity points. This will greatly reduce the repeated exception ...
Nkosi's user avatar
  • 3,296
2 votes
Accepted

Create objects corresponding to whichever field has value from among a list of fields

This const int STATUS_BASE = 1; const int STATUS_FIN = 2; const int STATUS_FINI = 3; const int STATUS_WAST = 4; const int STATUS_PRGR = 5; screams for an enum ...
Heslacher's user avatar
  • 51k
2 votes

Design Pattern to Add, Edit and Delete Records

Dependency inversion principle violation CategoriesController depend on Category[operation]Services (concrete implementations) ...
Aram Kocharyan's user avatar
2 votes

418 I'm a TeapotServer for RESTful integration-tests

You allow a server to reuse an existing context when calling BeginScope. Does this mean multiple integration tests could reuse a context? If so, how do you handle ...
dfhwze's user avatar
  • 14.2k

Only top scored, non community-wiki answers of a minimum length are eligible