49 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 ...
RubberDuck's user avatar
  • 8,921
32 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. ...
Telastyn's user avatar
  • 109k
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 ...
RubberDuck's user avatar
  • 8,921
22 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 ...
Flater's user avatar
  • 47.5k
21 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 ...
Greg Burghardt's user avatar
18 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 (...
Christian Sauer's 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.
Robert Harvey's user avatar
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, ...
Telastyn's user avatar
  • 109k
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 ...
Greg Burghardt's 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 ...
Robert Harvey's 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 ...
ChrisW's user avatar
  • 3,417
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 ...
rahulaga-msft's user avatar
11 votes
Accepted

Does Having DI Happen in the Composition Root go against the whole point of Dependency Injection?

Does Having DI Happen in the Composition Root go against the whole point of Dependency Injection? No. You should create the object graph in the Composition Root. I think that I understand the reason ...
Yacoub Massad's user avatar
11 votes

Is unit of work pattern really needed with repository pattern

The Unit-Of-Work pattern makes sense when you have a complex use case with several objects involved, often objects which map to different master-detail tables. As part of the use case, you want to ...
Doc Brown's user avatar
  • 203k
10 votes

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

Whatever the reason, this is poor practise. It is very anti-OO because packages or folders (whatever you want to call them), should have weak inter-dependencies. Classes (or files) inside them should ...
Oliver Watkins's user avatar
10 votes
Accepted

ASP.NET Core - Is using [FromServices] attribute bad practice?

This isn't a code smell or bad design at all. In fact, this is precisely why the [FromServices] attribute was created: Action Injection with FromServices Sometimes you don't need a service for more ...
Greg Burghardt's user avatar
9 votes
Accepted

Never using Models, only ViewModels

Would my Data project be considered the "Model" for my application? Yes, that's exactly what Model is supposed to be. Is this a right approach I believe it is. or could there be potential ...
Euphoric's user avatar
  • 37k
9 votes
Accepted

Where to put User Interface/Domain Model manipulation logic (transferring data from the view to Domain Model)

Bear in mind that the Model View Controller (MVC) principal has been hijacked and bastardized by the web development world. In a real MVC application the model view and controller are largely ...
squarewav's user avatar
  • 206
9 votes
Accepted

is "ASP.NET Membership" still a good choice for ASP.NET MVC authentication nowdays?

Yes. Asp.Net Membership is a bit outdated. Asp.Net Identity was introduced a few years ago to help solve some of the pain points with the older system. It supports third party OAuth through Google (...
RubberDuck's user avatar
  • 8,921
9 votes

How Common/Acceptable is it for a .NET developer to abstain from WebForms as a rule?

My observation is that WebForms is on the decline. There is a good reason for that. Having used WebForms extensively in the past, it's difficult to do something outside the box. In addition to the ...
Kasey Speakman's user avatar
8 votes

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

To answer your 'Why everyone...?' question: Here are some potential reasons, although I'm not entirely sure which combination of them is a real cause, since it is actually a subjective question To ...
Bishoy's user avatar
  • 271
8 votes
Accepted

Why use Razor Syntax?

More generally, you are asking about the benefits of using a template rather than generating content directly inside your source code. The answer is that mixing source code and HTML could be a viable ...
Arseni Mourzenko's user avatar
8 votes
Accepted

How can I move from Web Forms to ASP .NET MVC 5?

You're going to have to embrace ASP.NET MVC in its own right. There is no server code-behind. There are no drag-and-drop widgets, no plugins, and no leaky page life-cycle. There is no almost-wysiwyg:...
Robert Harvey's user avatar
8 votes
Accepted

Should integration tests use database?

1) Should these tests use real database data? I mean I'll have to connect to a real database? If you're testing the integration between your software and the database, then yes you should use the ...
amon's user avatar
  • 133k
8 votes

Is dependency injection always a best practice?

No pattern is always a best practice. Patterns are tools like a hammer or a wheelbarrow: The are useful for particular tasks, and you have to use them correct to get any benefit. If someone says "it ...
JacquesB's user avatar
  • 57.7k
7 votes
Accepted

Who does what in a Single Page Application?

So, I'm more experienced in PHP and Python but my answers should be valid for ASP .NET too, seen that your questions are more about the MVC structure rather than the language / framework itself. ...
edoardo849's user avatar
7 votes

Architect in our company is against DTO

It sounds as though your architect isn't against DTOs as much as your architect is against this DTO. They argue that having a DTO that is an Offer with a Date tacked on is a bit of a smell. I don't ...
Telastyn's user avatar
  • 109k
7 votes
Accepted

Mapping Domain models to ViewModel

Keep mapping implementation out of your controllers. Instead, call the thing responsible for mapping in your controller. public ActionResult FetchSomething() { var thingMapper = new ThingMapper();...
Scant Roger's user avatar
  • 9,038
7 votes
Accepted

When where and how to use ViewBag

A ViewBag is essentially a Dictionary, except that the syntax is a bit cleaner. Instead of writing myDict["SomeProperty"] you can access the dynamic dictionary's elements with first-class dot ...
Robert Harvey's user avatar
6 votes
Accepted

CRUD operations in DDD

The typical entry point for this in DDD is an Application Service. Application services orchestrate calls to repositories and domain objects. They also know about the current execution state and often ...
guillaume31's user avatar
  • 8,524

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