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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
4
votes
Method GetById and SingleResult
[EnableQuery] and SingleResult does in fact return 404 OOTB, that is one of the key reasons for ...
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 ...
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, ...
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:
...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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
...
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:
...
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 ...
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 ...
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.
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 ...
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 ...
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 ...
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 ...
2
votes
Design Pattern to Add, Edit and Delete Records
Dependency inversion principle violation
CategoriesController depend on Category[operation]Services (concrete implementations) ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
asp.net-web-api × 133c# × 128
entity-framework × 17
asp.net-mvc × 16
asp.net × 15
.net × 14
rest × 10
asp.net-core × 9
async-await × 8
repository × 8
api × 6
authentication × 6
xamarin × 6
error-handling × 5
design-patterns × 4
dependency-injection × 4
asp.net-mvc-4 × 4
jwt × 4
owin × 4
json × 3
http × 3
controller × 3
.net-core × 3
asp.net-core-webapi × 3
javascript × 2