Skip to main content
27 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
  • 9,021
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
  • 58.1k
21 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
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
  • 110k
13 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
  • 218k
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

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

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 real ...
amon's user avatar
  • 136k
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
  • 61.6k
6 votes
Accepted

How to incorporate external entity models in conceptual model?

IMHO you should model those objects to exactly the degree you need them in your application, no less, no more. For example, don't model all available attributes, just model the attributes which are ...
Doc Brown's user avatar
  • 218k
6 votes

Argument for staying on Rails instead of migrating to .net MVC?

You can give counter examples of large scale applications. With its 40.1 million users, GitHub is one of them. It is written using Ruby on Rails, and it doesn't seem to suffer a lot with the ...
Arseni Mourzenko's user avatar
6 votes
Accepted

Do "Unused" Variables In A View Model Get Passed To The Client In MVC?

The razor view is passed a reference to the Model, which is used to generate the HTML, which is sent to the client. The Model and its properties are not sent to the client unless you render them out ...
Ewan's user avatar
  • 81.9k
6 votes

Moving shared CQRS/Mediatr Request Handler logic into services and avoiding code/logic duplicity?

For context, I'm working in a similar architecture to yours, and recently I spent a few days investigating how to implement reusable logic that gets reused across commands - so I think we're looking ...
Flater's user avatar
  • 58.1k
6 votes
Accepted

How to unit test public method which internally calls many internal or private methods which are already individually unit tested

how do we test the public service methods in such a way that we don't have to duplicate the code/effort that we have already spent in testing the internal/private/helper methods? Don't unit test your ...
Philip Kendall's user avatar
5 votes
Accepted

How to model user management using UML class diagram?

1. How to model a patient ? Your design, with its Account, User, and the different derivates of users are already a good start. The Patient could indeed be a special kind of User. However, the ...
Christophe's user avatar
  • 81.4k
5 votes
Accepted

MVC - Problems with passing ViewModel directly to / from repository

I have several complex view models - usually subsets of a far larger model. Should I create items in the repository that take the ViewModels - then just use Dapper.net to map them to some SQL? ...
Ben Cottrell's user avatar
  • 12.1k
5 votes
Accepted

In an MVC Application, What Goes Where?

You are fully right on the principle. The MVC should have the business logic and the data access layer in the Model. The Controller should manage user input and transforms it into commands either for ...
Christophe's user avatar
  • 81.4k
4 votes
Accepted

Large controllers in ASP.NET WebAPI, How to organize

One of the benefits of the routing model in web api is that it allows you to completely separate the organisation of your URI structure from the underlying code layout. All the routing engine is doing ...
richzilla's user avatar
  • 1,143
4 votes

How to avoid double data validation in an application with web interface?

To recap/confirm: you have two layers of an application (in the same process space) where the outer layer of the application is performing validations that the inner layer is also performing. This is ...
JimmyJames supports Canada's user avatar
4 votes

Is it a good practice to have one bundle per view in Asp Net MVC

No. Due to browser caching, you get the best overall results by using the same bundle or bundles on all the pages. This means that the user will download all the css and js when they hit the first ...
Ewan's user avatar
  • 81.9k
4 votes
Accepted

Is it a good practice to have one bundle per view in Asp Net MVC

I think it might almost even be counterproductive to use a single bundle per page. There's an overhead for creation of the bundle... albeit, that overhead is incurred once per application instance (it'...
jleach's user avatar
  • 2,692
4 votes
Accepted

Where to put methods in a .NET Core MVC Web app?

The business logic should only be in the Model because this logic is technology-agnostic (it doesn't matter you wrote an ASP.NET or a PHP app, the business logic stays the same) and the only part of ...
Spotted's user avatar
  • 1,690
4 votes

How to incorporate external entity models in conceptual model?

OK so! your application is a "shift management app" In essence this app doesn't really care about employees and departments. It will care about when the business day starts and ends, how many people ...
Ewan's user avatar
  • 81.9k
4 votes
Accepted

Views are not classes how to put them in class diagram in MVC design pattern?

Behind the curtain, the cshtml gets transformed into a class. You could simply add a class node with a <<view>> stereotype and the relevant properties. Question is, what would be the ...
devnull's user avatar
  • 3,055
4 votes
Accepted

Argument for staying on Rails instead of migrating to .net MVC?

Sorry, yes its slow. https://www.techempower.com/benchmarks/ However, as noted performance of the language probably isn't very important compared to things like good database design and code written ...
Ewan's user avatar
  • 81.9k
4 votes

How do you manage objects that are shared between back-end services and front-end services/apps?

Most commonly you would need an assembly that defines the DTO objects that is shared between the front end and the back end. That doesn't necessarily have to be a NuGet package. It can simply be ...
Berin Loritsch's user avatar
4 votes
Accepted

How do you manage objects that are shared between back-end services and front-end services/apps?

It is just a DTO with the same properties. I would strongly suggest just copy it between the server and the client. See also this StackOverflow answer that has the same conclusion The reason is, in ...
Esben Skov Pedersen's user avatar
4 votes
Accepted

Multiple Applications, how to bring them together?

Here are some suggestions: keep the solutions in one repository. That is probably a no-brainer, since it does not enforce a specific project/solution structure. share common logic - well, simply ...
Doc Brown's user avatar
  • 218k
4 votes

Is it good practice to save an entire ViewModel in Session (C# ASP.NET MVC)

Putting all of your view model data in the session essentially creates global variables. If you have two different view models setting the same session key one will overwrite the other — and you ...
Greg Burghardt's user avatar
4 votes

Why do backend web frameworks use "MVC" when they have no persistent UI to update?

Again, I had it wrong originally, updated, and still might contain stuff wrong, If someone can write a proper answer I'm all for it. Okay, so I had it wrong. Updated: THE MVC The Model is the ...
mishan's user avatar
  • 211

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