This week's book giveaway is in the Cloud forum.
We're giving away four copies of Terraform in Action and have Scott Winkler on-line!
See this thread for details.
Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Dot Net Core Learning Path

 
Ranch Hand
Posts: 2550
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been learning Dot Net Core (mainly focusing on web application ). So far, I practiced some of the key concepts using a simple sample application (online shopping ) as listed below :

* Learnt to create a MVC flow by creating Controller,Model (POCO , repository),  View (Cshtml). Calling the controller with action name and it displays the view with associated model data.
* Learnt to create ModelView to display the data on cshtml view.
* Learnt to use Dependency Injection to inject instance of for example the  repository.

What else should I focus on as part of hands on exercises using simple sample application ?

Thanks.
 
Saloon Keeper
Posts: 13419
300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The bullet points you mentioned aren't specific to .NET Core, they are just as relevant to a .NET Framework application, or even frameworks in a completely different language.

I don't think there is much point to aimlessly learning a framework for the sake of learning the framework.

What kinds of applications would you like to write when you feel you've learned enough of the framework to do it?
 
Monica Shiralkar
Ranch Hand
Posts: 2550
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
I have been using Java in my career.In my current company mainly work is on Dot Net MVC web applications.I learnt C# in this company and worked on it but not much into dot net web applications yet .At present majority applications here are on Dot Net Framework and later on all new development  will be on Dot Net Core. I understood your point that these are not specific for Dot Net Core but I am not someone who has been working on Dot Net Framework and now learning Dot Net Core.Instead my case is of a developer who is trying to learn Dot Net MVC web applications for the first time.
 
Stephan van Hulst
Saloon Keeper
Posts: 13419
300
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, because your initial post led me to believe that your focus was on .NET Core, not on ASP.NET Core MVC.

I strongly suggest you practice your skills by writing a web application that makes AJAX requests to a REST API, that also uses single sign-on and role- or claims-based security.

For instance, extend your shopping application by allowing users to create accounts based on a Facebook or Google account. Make it possible to assign roles to a user, such as an "Administrator" role so that such users can administrate your shopping application through an admin page, or maybe a "Seller" role to allow a user to maintain the products they are selling on your website.

Make your regular controllers only return a view, and let scripts in the view use your REST API to perform actions and update the view. These are essential skills in modern day web application development.
 
Monica Shiralkar
Ranch Hand
Posts: 2550
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:

For instance, extend your shopping application by allowing users to create accounts based on a Facebook or Google account. Make it possible to assign roles to a user, such as an "Administrator" role so that such users can administrate your shopping application through an admin page, or maybe a "Seller" role to allow a user to maintain the products they are selling on your website.



Thanks a lot for the good suggestion.


Make your regular controllers only return a view, and let scripts in the view use your REST API to perform actions and update the view. These are essential skills in modern day web application development



Does that mean for instance have only a homepage view returned from an action and rest from all other actions , return AJAX JSON string and thus on any button click on the home page , the scripts will return AJAX JSON and not view .

I have a question .If the home page has a menu and one of the menu items is products then on click of products, should it open a different CSHTML view for displaying products  or instead in the same Home CSHTML view ,show products using AJAX ?



 
Stephan van Hulst
Saloon Keeper
Posts: 13419
300
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can certainly create a web application where there is only one CSHTML view, and everything that the user sees will be a part of this view that is made visible by JavaScript, and possible filled with additional data using AJAX. This is called a Single Page Application or SPA.

Personally I'm not a big fan of such web applications, I prefer to return a different view from the server side for different parts of the site, but it seems like an important skill to have nonetheless.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:The bullet points you mentioned aren't specific to .NET Core, they are just as relevant to a .NET Framework application, or even frameworks in a completely different language.

I don't think there is much point to aimlessly learning a framework for the sake of learning the framework.

What kinds of applications would you like to write when you feel you've learned enough of the framework to do it?



I'm re-learning JavaScript and expect it will keep me occupied well into 2020.
 
Monica Shiralkar
Ranch Hand
Posts: 2550
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:You can certainly create a web application where there is only one CSHTML view, and everything that the user sees will be a part of this view that is made visible by JavaScript, and possible filled with additional data using AJAX. This is called a Single Page Application or SPA.

Personally I'm not a big fan of such web applications, I prefer to return a different view from the server side for different parts of the site, but it seems like an important skill to have nonetheless.



Thanks a lot. This will be immensely helpful.

Earlier ,I had heard about SPAs in the context of application development  using Java Script frameworks like Angular ,React . I will explore and practice .Also , I will read on the pros and cons of using SPAs.
 
Monica Shiralkar
Ranch Hand
Posts: 2550
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:You can certainly create a web application where there is only one CSHTML view, and everything that the user sees will be a part of this view that is made visible by JavaScript, and possible filled with additional data using AJAX. This is called a Single Page Application or SPA.



Does this mean login page included in SPA or Homepage onwards all will be as SPA while login page can be separate?
 
Stephan van Hulst
Saloon Keeper
Posts: 13419
300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a true SPA, everything is covered by a single web page, including log-in.
 
Monica Shiralkar
Ranch Hand
Posts: 2550
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks
 
Monica Shiralkar
Ranch Hand
Posts: 2550
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:
Make your regular controllers only return a view, and let scripts in the view use your REST API to perform actions and update the view.



I have been practicing using this.This way there is 1 CSHTML which I call home.cshtml (in addition to the layout.cshtml) and several Java Script files.

By REST APIs does it mean Controller APIs or instead Controller APIs calling the Web APIs?. As of now I implemented Controllers APIs but I think having controller APIs call the Web APIs is a better way since it gives the flexibility that tomorrow the same APIs can be used in some other front-end.
 
Stephan van Hulst
Saloon Keeper
Posts: 13419
300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Be careful in your terminology. Nobody says "Controller API" and the term "Web API" is usually used to refer to the REST API, not the controllers that serve the web page. After all, the web page is not an API.

Use "API controller" to refer to a controller that serves data like XML or JSON to a client. Use "regular controller", "web controller" or just "controller" to refer to a controller that serves a web page.

Your web controller (which would only serve a single web page) and your API controllers are completely separate. One does not call the other. The web controller just serves the web page, and scripts that are part of the web page will call the API controllers through AJAX.

To create a web controller, extend the Controller class, and annotate it with the ControllerAttribute attribute. To create an API controller, extend the ControllerBase class and annotate it with the ApiControllerAttribute attribute:

 
Monica Shiralkar
Ranch Hand
Posts: 2550
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
So , based on this I can see my code (which although is working fine ) has some problems.




The above code is part of controller which extends Controller.So that makes it web controller.

Surprisingly , I am not using it as web controller though as this method is called from the Java Script through Ajax and does not return web page.

While it is working fine , I think I should better change it to API controller by extending ControllerBase class instead of Controller.
 
Stephan van Hulst
Saloon Keeper
Posts: 13419
300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Extending Controller won't really break your API controller, but it will contain more functionality than it needs.

A bigger problem is that you made your search action a POST request. Why? A search action generally shouldn't change server state.

I also believe that newer versions of ASP.NET don't require you explicitly return a JsonResult if you want your responses to be serialized as JSON. Instead, return an ActionResult<TValue> (or a Task<ActionResult<TValue>> for async actions), where you substitute your data contract for TValue. If you want, you can then specify the content type explicitly using the ProducesAttribute, but I believe JSON is the default. For instance, you could do this:
 
Monica Shiralkar
Ranch Hand
Posts: 2550
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks .Yes it should be GET.
Both the return types are working fine the JsonResult and ActionResult and I don't need to specify JsonResult. I think the clear advantage of changing the Web controller to  API controller will be that the same APIs can be used for some different front end too.
 
Monica Shiralkar
Ranch Hand
Posts: 2550
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed the class to instead extend API Controller.However, it started giving me the below error :

Cannot implicitly convert type 'System.Web.Http.Results.JsonResult<System.Collections.Generic.IEnumerable<OnlineShopping.Models.Pie>>' to 'Microsoft.AspNetCore.Mvc.IActionResult'.

The line in code which gives this error is the one where I return the Json.


I will check further on resolving this issue.
 
Monica Shiralkar
Ranch Hand
Posts: 2550
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I could resolve it using a different way though.

Instead of returning ActionResult,is it fine to simply do as below.

The below works fine.

 
Stephan van Hulst
Saloon Keeper
Posts: 13419
300
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, but this will make it harder to return specific HTTP status codes. For instance, if the keyword needs to conform to some kind of format, you might want to return a Bad Request HTTP status code if the client sends the keyword in a wrong format:

But yes, if you're certain that you never want to return specific status codes from your actions, you can directly return your data type, instead of ActionResult.
 
Monica Shiralkar
Ranch Hand
Posts: 2550
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks .I could resolve the issue and thus use ActionResult.
 
Monica Shiralkar
Ranch Hand
Posts: 2550
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:You can certainly create a web application where there is only one CSHTML view, and everything that the user sees will be a part of this view that is made visible by JavaScript, and possible filled with additional data using AJAX. This is called a Single Page Application or SPA.



For all the code I implemented so far in the sample application ,I made into a SPA (so far ).

So there is 1 cshtml and multiple JavaScript files. Most of these files calls some Web API , build dynamic html content using the response and sets it in a div on the cshtml page.

I have a question.With multiple JavaScript files do we have to make sure that there is no duplication of code (the html contents built from response)? If so ,how ?

Thanks
 
Stephan van Hulst
Saloon Keeper
Posts: 13419
300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The same way you do it in other applications. What makes JavaScript different from C# in this regard?
 
Monica Shiralkar
Ranch Hand
Posts: 2550
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Say I have 1 cshtml page and 2 JavaScript files : listProducts.js,productOfTheWeek.js.

listProducts.js calls a web API getProducts and builds dynamic html code using the response to list the attributes : name,price,image,description.
Finally it sets this html in a div in the cshtml.

productsOfTheWeek.js calls a web API getProductsOfTheWeek and builds dynamic html code using the response to list the attributes : name,price,image,description.
Finally it sets this html in a div in the cshtml.

If we notice ,in these 2 js files the attributes to be listed are the same.So in this case duplication of code will be there .How can this be avoided ?

Thanks




 
Stephan van Hulst
Saloon Keeper
Posts: 13419
300
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By doing it all in one file, and calling the function in that file from your other files.
 
Monica Shiralkar
Ranch Hand
Posts: 2550
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. Yes that would certainly solve this. As you said earlier, that's the same way we do in any other language.
 
Stephan van Hulst
Saloon Keeper
Posts: 13419
300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you write different JavaScript files that are responsible for different things, just the same as Java or C#. With 'vanilla' JavaScript, you can make this process easier by relying on a library like RequireJS, which you can use to load dependencies that your scripts require.

These days however, I don't recommend writing 'vanilla' JavaScript, but ES6 instead. In ES6 you can easily write classes, and you can use import statements to load classes from other files.
 
Monica Shiralkar
Ranch Hand
Posts: 2550
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Okay, because your initial post led me to believe that your focus was on .NET Core, not on ASP.NET Core MVC.

I strongly suggest you practice your skills by writing a web application that makes AJAX requests to a REST API, that also uses single sign-on and role- or claims-based security.

For instance, extend your shopping application by allowing users to create accounts based on a Facebook or Google account. Make it possible to assign roles to a user, such as an "Administrator" role so that such users can administrate your shopping application through an admin page, or maybe a "Seller" role to allow a user to maintain the products they are selling on your website.

Make your regular controllers only return a view, and let scripts in the view use your REST API to perform actions and update the view. These are essential skills in modern day web application development.



As I have been practicing using my sample application, I realise that more than Dot Net Core , it helped me learn/improve some other skills on web development like JQuery,Ajax ,CSS,HTML,Bootstrap.Also, I will learn XUnit. If apart from these there is any other web development skill which is good to focus during my practice ,please do let me know.
 
Stephan van Hulst
Saloon Keeper
Posts: 13419
300
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should probably focus on one thing at a time.

I also strongly discourage you from using Bootstrap. It's a terrible framework that just turns your HTML into spaghetti.

JQuery is also on its way out. You don't really need it. Write ES6 instead.
 
Monica Shiralkar
Ranch Hand
Posts: 2550
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.  This application specially because of being a SPA , more that Dot Net Knowledge required me to know some Web development. For example. I created several  Dot Net Core Web APIs here but mostly I was working with updating the UI using the JS.

This way it also helped me get comfortable with web development.I am happy for that too.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic