2022 Developer Survey is open! Take survey.
296 votes
Accepted

Should you write your back-end as an API?

Yes you should. It not only makes your back end re-usable but allows for more security and better design. If you write your backend as part of a single system, you're making a monolithic design that'...
user avatar
  • 48k
96 votes

Should you write your back-end as an API?

You cannot possibly avoid building an API. Even if you build "just a Website", it will still need to get its data from your backend somehow. However you decide to do this, that is your de facto API. ...
user avatar
66 votes
Accepted

If MVC is "Separation of Concerns" then why was Razor Syntax introduced?

You are conflating the Razor syntax with separation of concerns. Separation of concerns has to do with how you structure your code. Being able to use C# in views doesn't prevent that. It has nothing ...
user avatar
  • 52.6k
63 votes

Should you write your back-end as an API?

I know microservices are all the rage right now, but they aren't always worth it. Yes, loosely coupled code is the goal. But it shouldn't come at the expense of a more painful development cycle. A ...
user avatar
  • 747
53 votes
Accepted

Is FormsAuthentication obsolete?

Yes. FormsAuthentication is deprecated in MVC 5 and onwards. At least, that's the short answer. The long answer is that pre-MVC 5 traditional FormsAuthentication is still ok to use. It is, however ...
user avatar
47 votes
Accepted

Why does everyone put controllers in one folder and views in another?

I'd like to say it's cargo cult programming, but there are technical reasons for this structure. Asp.Net MVC took a convention over configuration approach to nearly everything. By default, the Razor ...
user avatar
  • 8,841
35 votes

If MVC is "Separation of Concerns" then why was Razor Syntax introduced?

Rather than directly answer the question, my response questions the assumption made in the question. That is, the assumption that Razor was built for MVC is incorrect. I work at Microsoft on the ASP....
user avatar
  • 459
35 votes

Should you write your back-end as an API?

No you shouldn't. If you don't have immediate plans to create alternative frontends (like mobile or desktop apps or separate web application) which access the same backend, then you shouldn't ...
user avatar
  • 54.6k
30 votes
Accepted

Why would you ever 'await' a method, and then immediately interrogate its return value?

As I understand it, asking for the Task's value in this manner will block code execution until the value from the awaited method is returned, effectively making this a synchronous call. Not quite. ...
user avatar
  • 107k
29 votes

Should you write your back-end as an API?

My company has one application built like this. Initially we were commissioned to build a back end with API for a front end that another developer was creating. When the other developer couldn't ...
user avatar
25 votes

Why would you ever 'await' a method, and then immediately interrogate its return value?

I really hate that none of the examples show how it’s possible to wait a few lines before awaiting the task. Consider this. Foo foo = await getFoo(); Bar bar = await getBar(); Console.WriteLine(“Do ...
user avatar
  • 8,841
24 votes
Accepted

Should an ASP.NET MVC application directly use Entity Framework as the model?

In my applications I have always separated things out, with different models for the database (Entity Framework) and MVC. I have separated these out into different projects too: Example.Entities - ...
user avatar
  • 1,374
23 votes
Accepted

Why is there no WSDL type support for Web Api?

SOAP, REST AND PEOPLE'S CREATIVITY SOAP needs a description document like WSDL because each resource can be consumed with different messages, there are no definition on the protocol about constraints ...
user avatar
22 votes

Should you write your back-end as an API?

It depends on the type of application and the type of market you are in. There are trade-offs and benefits to going this way. It is not a clear-cut answer that one way is better than the other. I'...
user avatar
20 votes
Accepted

Is that good idea to add ViewModel exactly same as Model

This may look like a violation of the DRY rule initially, but I'd argue that "similar, and even identical, code" isn't necessarily "repetition" if it does something different or is able to change ...
user avatar
  • 13.2k
20 votes
Accepted

Difference between 3-Tier architecture and MVC (Model, View Controller) in ASP.Net

This is like asking what the difference is between an apple and an apple core. These two architectures aren't replacements for one another. I think a more accurate view is that the 3-tier architecture ...
user avatar
18 votes

Is this a good practice or not?

This sounds suspiciously like an inner platform. Here are the potential problems: You'll be writing queries that query the database for what information to query (metaqueries) first, rather than ...
user avatar
17 votes
Accepted

Server side C# MVC with AngularJS

You can certainly use any mix of client-side rendering and server-side rendering, but I would recommend against trying to mix ASP.NET MVC helpers with AngularJS directives. It might seem like a good ...
user avatar
17 votes
Accepted

What is "presentation logic" and how much is acceptable in views?

Presentation logic comprises the logic and calculations that are needed to present the business data in the right way for a particular view. For complex graphical views, this can be quite complex ...
user avatar
17 votes

A property that can represent both a single date and a date range: How to properly model that?

Use a date range (i.e. two dates) for all shipping estimates. For a single date, make X and Y equal.
user avatar
17 votes
Accepted

How can I integrate Python code with c# code?

Ok, we have done this. I would advise you to use a microservice architecture: e.g. your code calls a Python Rest Service which computes the data and returns the result. Or if the operation is long (...
user avatar
15 votes

This way I'm writing this code is testable, but is there something wrong with it I'm missing?

This design is known as Service Locator* and I don't like it. There are lots of arguments against it: Service Locator couples you to your container. Using regular dependency injection (where the ...
user avatar
14 votes

Separating ASP.NET IdentityUser from my other entities

You can create a User class that has nothing to do with ASP.NET Identity in your core library. public class User { public Guid UserId { get; set; } public string UserName { get; set; } ...
user avatar
  • 339
14 votes
Accepted

Is dependency injection always a best practice?

Is dependency injection always a best practice? Yes, passing your dependencies into their consumers is always a best practice. It allows flexibility in managing those dependencies, ease of testing, ...
user avatar
  • 107k
13 votes
Accepted

What is the purpose of domain/business logic in classes when having repositories?

What is the purpose of domain/business logic in classes when having repositories? This is kind of like asking: What is the purpose of cars when we have garages? The reason is that Business ...
user avatar
12 votes
Accepted

Are Repositories needed any longer in ASP.net 5 & EF7?

If you're adding methods to a repository like GetById GetByName GetWithIncludesABC GetWithIncludes123 Then you're better off moving to a Service Layer, and letting the Service Layer use EF ...
user avatar
12 votes
Accepted

Can I store a handful of constant complex objects in an enum-like structure in C#?

You could do that like this: class Region { public string name { get; private set; } public string id { get; private set; } public string url { get; private set; } // private ...
user avatar
  • 3,357
12 votes
Accepted

Is copying a C# class library from one solution to another the only way to "share" that library?

Shortest answer ever : publish reusable library with required dependencies as NuGet package and install it wherever you need. It will help you in versioning as well. If your class library is .NET ...
user avatar
12 votes
Accepted

Is unit of work pattern really needed with repository pattern

The Entity Framework DbContext is a unit of work, and its DbSet<T> properties are repositories. That's not to say that you should never roll your own layer on top of them, but you're correct in ...
user avatar
  • 37.3k

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