In This Article:
NetLearner: What is it?
NetLearner is an ASP .NET Core web app to allow any user to consolidate multiple learning resources all under one umbrella. The codebase itself is a way for new/existing .NET developers to learn ASP .NET Core, while a deployed instance of NetLearner can be used as a curated link-sharing web application.
NetLearner on GitHub: https://github.com/shahedc/NetLearnerApp
Restrictions
Registration for each web app has been disabled by default. To enable registration, please do the following:
- Locate scaffolded Identity pages under /Areas/Identity/Pages/Account/
- In Register.cshtml, update the page to include environments in addition to Development, if desired.
- In Register.cshtml.cs, replace [Authorize] with [AllowAnonymous] to allow access to registration
Architecture
The current version of NetLearner on Github includes a shared .NET Standard Class Library, used by multiple web app projects. The web apps include:
- MVC: familiar to most ASP .NET developers
- Razor Pages: relatively new in ASP .NET
- Blazor: the latest offering from ASP .NET
Future updates will also include:
- Web API, exposed for use by other consumers
- JavaScript front-end web app(s)
Note that an ASP .NET Core web app can contain various combinations of all of the above. However, the purpose of the NetLearner application code is to demonstrate how to achieve similar results using all of the above. So, each of the web app projects will be developed in parallel, using a shared library.
Shared Library
The shared library is a .NET Standard 2.1 library. This version was selected because .NET Core 3.x supports .NET Standard 2.1, as seen in the official documentation.
.NET Standard: https://docs.microsoft.com/en-us/dotnet/standard/net-standard
The shared library contains the following:
- Database Context: for use by Entity Framework Core
- Migrations: for EF Core to manage the (SQL Server) db
- Models: db entities, used by web apps
- Services: service classes to handle CRUD operations
Using terms from Clean Architecture references, you may think of the DB Context and Migrations as part of the Infrastructure code, while the Models and Services are part of the Core code. For simplicity, these are all kept in a single library. In your own application, you may split them up into separate assemblies named Core and Infrastructure.
Running the Application
In order to run the web app samples, clone the following repository:
NetLearner: https://github.com/shahedc/NetLearnerApp
Here, you will find at least 4 projects:
- NetLearner.SharedLib: shared library project
- NetLearner.Blazor: Blazor server-side web project
- NetLearner.Mvc: MVC web project
- NetLearner.Pages: Razor Pages web project
To create a local copy of the database:
- Open the solution file in Visual Studio 2019
- In the Package Manager Console panel, change the Default Project to “NetLearner.SharedLib” to ensure that EF Core commands are run against the correct project
- In the Package Manager console, run the Update-Database command
- Verify that there are no errors upon database creation
To run the samples from Visual Studio 2019:
- Run each web project one after another
- Navigate to the links in the navigation menu, e.g. Lists and Resources
- Add/Edit/Delete items in any of the web apps
- Create one or more lists
- Create one more resources, assign each to a list
- Verify that your data changes are reflected no matter which web app you use
What’s Next?
In 2020, you can expect a new A-Z weekly blog series to cover 26 different topics from January through June 2020. To get a sneak peek of what’s to come, take a peek at the 2019 A-Z series.
I hope to try it soon. Would the app be useful in say recreating asp.net mvc app in asp.net core?? can that be extended to do aspnet-webform to asp.net core??
Hi there… let me try to answer to the best of my ability.
Q1. Would the app be useful in say recreating asp.net mvc app in asp.net core??
A1. If you want to use this app as a template to create your own project, I would advise against it. You could use it as a reference instead. Also, refer to my recent post about how to create a web app project with a shared library, from scratch.
https://wakeupandcode.com/asp-net-core-code-sharing-between-blazor-mvc-and-razor-pages/
Q2. can that be extended to do aspnet-webform to asp.net core??
A2. Web Forms are not supported on ASP .NET Core. Instead, current/former Web Forms developers are encouraged to take a look at Blazor as a possible alternative.
Hi, could you walk us through the deployment process if we were to host this app on Azure App Service?
Hi Sandy, I’ll cover deployment steps as part of my 2020 A-Z series. (A for Authentication/Authorization… D for Deployment!)
So you can expect it in about 4 weeks 🙂
In the meantime, check out my 2019 post for reference:
https://wakeupandcode.com/deploying-asp-net-core-to-azure-app-service/
Sure thanks
Pingback: Dew Drop – January 2, 2020 (#3103) | Morning Dew
Pingback: Authentication & Authorization in ASP .NET Core 3.1 | Wake Up And Code!
Pingback: Blazor Full-Stack Web Dev in ASP .NET Core 3.1 | Wake Up And Code!
Pingback: Cookies and Consent in ASP .NET Core 3.1 | Wake Up And Code!
Pingback: Deploying ASP .NET Core 3.1 to Azure App Service | Wake Up And Code!
Wish you hadn’t used ASP.NET Core 2.1 shared library, but 3.1 instead. I’ve only found one or two trainings that are honestly 3.1, the rest are basically 2.x saying they are 3.1, and most saying that there are “very few changes” between the versions. I disagree.
And I think your title saying it is 3.1 is misleading. I was so excited until I read further down in the article to see you were using 2.1 shared library. Bummer. That isn’t helping me learn 3.1.
Are you saying that you can’t do this in 3.1, that you HAVE to use 2.1 to make it work? Or that you haven’t taken the time to change things over to 3.1? Or that you want to use the 2.1 way of doing things and don’t believe in the 3.1 way of doing things? When you fully use 3.1 then please comment so I know to come back.
To prevent maintenance issues, I am fully committed to writing new code in full 3.1. If anyone knows other training available that is fully 3.1, and hopefully talks about the 3.1 way of doing things and how it differs from 2.1 thinking and code, please leave a comment on what it is; I’d appreciate it. That would make a great article if anyone wants to write it here or elsewhere.
Hi Pam,
The good news is that this article and blog series absolutely uses ASP .NET Core 3.1 from the beginning until the end, *including* the Shared Library.
FYI: The Shared Library assembly targets NET Standard 2.1, which is a standard and not a runtime. This 2.1 version of .NET Standard maps to .NET Core 3.1, and as a result, ASP .NET Core 3.1.
For more details on .NET Standard versioning, please refer to the following:
* shared library setup: https://wakeupandcode.com/asp-net-core-code-sharing-between-blazor-mvc-and-razor-pages/
* official docs: https://docs.microsoft.com/en-us/dotnet/standard/net-standard
* Scott Hanselman article: https://www.hanselman.com/blog/HowToReferenceANETCoreLibraryInWinFormsOrNETStandardExplained.aspx
In a nutshell: the sample code, its shared library and the articles are all using the latest version of everything.
Thanks for commenting, and feel free to reach out with any follow-up questions.
Hope this helps!
– Shahed
Pingback: EF Core Relationships in ASP .NET Core 3.1 | Wake Up And Code!
Pingback: Forms and Fields in ASP .NET Core 3.1 | Wake Up And Code!
Pingback: Generic Host Builder in ASP .NET Core 3.1 | Wake Up And Code!
Pingback: Handling Errors in ASP .NET Core 3.1 | Wake Up And Code!
Pingback: IIS Hosting for ASP .NET Core 3.1 Web Apps | Wake Up And Code!
Pingback: JavaScript, CSS, HTML & Other Static Files in ASP .NET Core 3.1 | Wake Up And Code!
Pingback: Key Vault for ASP .NET Core 3.1 Web Apps | Wake Up And Code!
Pingback: Logging in ASP .NET Core 3.1 | Wake Up And Code!
Just found this. Very excited to read more.
Thanks for reading, Andy!
Pingback: Middleware in ASP .NET Core 3.1 | Wake Up And Code!
Pingback: .NET 5.0, VS2019 Preview and C# 9.0 for ASP .NET Core developers | Wake Up And Code!
Pingback: Organizational Accounts for ASP .NET Core 3.1 | Wake Up And Code!
Pingback: Production Tips for ASP .NET Core 3.1 Web Apps | Wake Up And Code!
Pingback: Query Tags in EF Core for ASP .NET Core 3.1 Web Apps | Wake Up And Code!
Pingback: Razor Pages in ASP .NET Core 3.1 | Wake Up And Code!
Pingback: SignalR in ASP .NET Core 3.1 | Wake Up And Code!
Pingback: Tag Helper Authoring in ASP .NET Core 3.1 | Wake Up And Code!
Pingback: Unit Testing in ASP .NET Core 3.1 | Wake Up And Code!
Pingback: Worker Service in .NET Core 3.1 | Wake Up And Code!
Pingback: XML + JSON Output for Web APIs in ASP .NET Core 3.1 | Wake Up And Code!
Pingback: YAML-defined CI/CD for ASP .NET Core 3.1 | Wake Up And Code!
Pingback: Zero-Downtime* Web Apps for ASP .NET Core 3.1 | Wake Up And Code!
Pingback: Validation in ASP .NET Core 3.1 | Wake Up And Code!