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 ...
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 ...
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 (...
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, ...
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
...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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?
...
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 ...
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 ...
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 ...
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 ...
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'...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
asp.net-mvc × 559c# × 172
asp.net × 85
mvc × 68
design-patterns × 56
.net × 49
entity-framework × 48
architecture × 43
design × 29
asp.net-core × 23
web-development × 22
domain-driven-design × 20
javascript × 19
authentication × 17
web-services × 15
asp.net-mvc-web-api × 15
dependency-injection × 14
unit-testing × 13
web-api × 13
asp.net-mvc-4 × 13
rest × 12
wcf × 12
asp.net-mvc-3 × 12
object-oriented-design × 11
sql-server × 11