.NET Core and Entity Framework - asp.net-core

I was reading through some of the microsoft .net core documentation and stumbled across this page: https://learn.microsoft.com/en-us/aspnet/core/data/ef-mvc/
Does the following quoted text (more specifically the last bullet point) imply that the MVC approach is no longer the recommended approach moving forward? Is this just a microsoft thing or general for any development that was based on the MVC approach?
This tutorial teaches ASP.NET Core MVC and Entity Framework Core with
controllers and views. Razor Pages is a new alternative in ASP.NET
Core 2.0, a page-based programming model that makes building web UI
easier and more productive. We recommend the Razor Pages tutorial over
the MVC version. The Razor Pages tutorial:
Is easier to follow.
Provides more EF Core best practices.
Uses more efficient queries.
Is more current with the lastest API.
Covers more features.
Is the preferred approach for new application development.

Razor Pages are still MVC, they just greatly simplify your code. Rather than having a distinct Model in one directory, a Controller in another directory, and a View in yet another directory, it keeps everything together in two files: A "View" (.cshtml) and a "Controler/Model" (.cs).
If you look at enough ASP.NET MVC applications you quickly notice how often there is a 1:1 relationship between the Views and their Controllers. In most cases, you find the Controller contains one method per View that consists of little more than return View();. Razor Pages helps solve this issue.
This does not change the fundamental value proposition of MVC and it's clear separation of concerns. It also isn't an either/or proposition. You can absolutely mix the traditional MVC structure and Razor Pages in the same web app.

Related

ASP.NET Core AddContext

I'm architecting a new App and I really unconfortable with this approach in ASP.NET Core that made "normal" adding a DbContext by using AddDbContext, in services.
I'd like to know if you guys think that using AddDbContext in ASP.NET Core isn't a bad practice, since it forces my Web App to have a dependecy on my database access layer.
I've researched a lot and it was incredible that there isn't almost anything that cover this subject.
How should I proceed to overcome this concern?
Thanks!
it forces my Web App to have a dependency on my database access layer
That's exactly the place where it should be: the composition root. Your application startup code is the place where you glue your components together.
What else would you want, create a separate library, containing interfaces for all classes in your entire DAL, and wire that up using magic during startup?

ASP.NET Core MVC View Components

In ASP.NET Core MVC (formerly MVC 6) there is a new area of functionality called View Components which appear to be a better alternative to Partial Views. I've seen the following View Component Example. But there doesn't seem much more information currently as to their usage.
I'm trying to evaluate if its worth using this pattern and if this can/(or is intended) to be used as a more baked in method to help with donut caching.
View components are definitively great and it's certainly an improvement. The one big improvement is that you can run asynchronous operations on view components where it wasn't possible with child actions.
More information available here:
Exciting Things About ASP.NET vNext Series: MVC View Components
For donut caching, there are two separate issues filed that you can comment/track: #1232 and #536
Currently there is available a brand new documentation from Microsoft:
View Components documentation.
In my opinion ViewComponents are very useful and flexible features. I like them, and I can recommend them.
However not always View Component is "a better alternative to Partial Views" - this will depend on your particular case.

WebForms view engine is slower that Razor view engine in MVC4

I am still a beginner to MVC and I was trying to understand why developers seem to prefer Razor engine over WebForms engine in ASP.Net.
My question: Is it because Webforms engine is slower than Razor engine?
Personally, Webforms engine comes more easily to me because I have been coding in Webforms for the last 12 years.
Performance wise there should be no difference. The razor engine was developed to give a more concise syntax as explained in the question Does Razor syntax provide a compelling advantage in UI markup?. What will give you a performance boost is removing the unused view engines. For example if you use only razor, then in the Global.asax.cs file
// Remove view engines except razor
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());

Areas in different project with ASP.NET MVC 4

I am working with ASP.NET MVC 4, and trying to have areas in separate projects.
I have been checking this thread where we are anticipated the non-supporting state of areas in different projects after ASP.NET MVC2:
What are the pros and cons of Areas implemented as single projects vs multiple projects in asp.net mvc
Anyone know if it is true that it is not supported anymore?
Could anyone help me to find out if there is a common way to have areas in separated projects when using ASP.NET MVC 4?
I have found this other thread that may help, but was looking for a more common way:
ASP.NET MVC 4 Areas in separate projects not working (view not found)
Thank you!
The answer is most likely no, but I can't provide a definitive source as it concerns > version 3.
This was written in 2010:
I'm the development lead on ASP.NET MVC at Microsoft.
There are no plans to include multi-project areas in ASP.NET MVC 3.
However, it's definitely an area that we plan to revisit in the
future.
In the meantime MvcContrib's solutions are probably the best bet. The
MVC Futures download still includes an old (and perhaps only
semi-functional) version of the original multi-project areas feature.
Because the full source code for it is also available, you might be
able to construct a solution that is customized to your needs.
Currently, the areas template as provided in VS2013 does not provide an out of the box solution for this. My assumption would be that it is "possible" but not supported. The greater question would be, what scenario are you encountering where it is necessary to put your areas into different projects?
Different projects are like different sites in one solution. They do not depend on each others. Each Area has own routing registration.
You can check this. May be it will help:
ASP.NET MVC 4 Areas in separate projects

Are Nhibernate Helper Kits available for VS2008?

Can you provide some information on Nhibernate Helper Kits for VS2008 and which all are open source and which all are not. Can you also share some links that gives information on using NHibernate with ASP.NET MVC.
Not sure what you mean by helper kits.
As far as using ASP.NET MVC with NHibernate Jeffrey Palermo's blog has a lot of good information on the topic. He goes into great depth in his book ASP.Net MVC in Action. Worth the read.