Results 1 to 8 of 8

Thread: MVC Core Lessons

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    MVC Core Lessons

    I've been doing a lot of development with ASP.NET (C#) as our back-end framework, but everything that I've done has been in .NET (not .NET Core) and I'm working off of a base stack where the nitty-gritty stuff to get the application stood up is already in place.

    I'm wanting learn how to get an ASP.NET Core application stood up from scratch, but I'm having a bit of a difficult time doing so.

    I followed MSDN's documentation (here) but a lot of the stuff like scaffolding the identity schema using Entity Framework code-first scaffolding sort of gets glossed over.

    I've looked at Exam 70-486: Developing ASP.NET MVC Web Applications, but I can't tell if this is .NET framework or .NET Core and it is also set to expire at the end of January.

    Do y'all have suggestions on any free or commercial websites that y'all really like?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: MVC Core Lessons

    Subscribing/following because at some point, I'd like to figure this out too.

    I've looked at Exam 70-486: Developing ASP.NET MVC Web Applications, but I can't tell if this is .NET framework or .NET Core and it is also set to expire at the end of January.
    My guess is if it is expiring that early, it's not for .NET Core.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: MVC Core Lessons

    I don't know why this is in Chit-Chat. I think General Developer would be better, but I'll be following along, as well.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: MVC Core Lessons

    I honestly thought it'd get more traction in chit-chat, but I went ahead and moved it to general developer forum.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  5. #5
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: MVC Core Lessons

    Dont know any specific resources, but i use .NET Core pretty much exclusively now for apps at work.

    happy to help and post some code if you want, which areas are you having trouble with?
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  6. #6

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: MVC Core Lessons

    Mainly getting it stood up.

    I created a blank project, setup the DBContext, use the EF scaffolder to build the identity tables, and stubbed out a simple controller to do basic CRUD operations with the idea that for now I'd run Postman or Insomnia to hit the controllers until I built out my UI.

    Right out the gate I'm having issues with IIS not wanting to run as well as issues with the dependency injection that my service layer is reliant upon.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  7. #7
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: MVC Core Lessons

    ah ok so when you say IIS not wanting to run do you mean when you deploy or just debugging ?

    Here is a fairly simple example with just a single service injected and consumed by a controller with a single Get method, also i added in the AutoMapper setup

    Dependency injection in .Net Core is not that different i tend to do by creating a seperate static IoC class.

    Code:
    public static class IoC
    {
        public static void Initialise(IServiceCollection services)
        {
            services.AddTransient<ICaseService, CaseService>();
        }
    }
    and then calling that class on Startup at the end of configure services

    Code:
    public void ConfigureServices(IServiceCollection services)
    {
           services.AddSingleton(AutoMapperConfig.CreateMapperConfig());
          
          services.AddDistributedMemoryCache();
          services.AddSession();
          services.AddControllersWithViews()
    
          IoC.Initialise(services);
    }
    then a controller would look something like

    Code:
    public class CaseController : BaseController
        {
            private readonly IMapper _mapper;
            private readonly ICaseService _caseService;
    
        public CaseController(ICaseService caseService, IMapper mapper)
        {
                _caseService = caseService;
                _mapper = mapper;
        }
    
            [HttpGet]
            public async Task<IActionResult> GetMyCases()
            {
                try
                {
                    var result = await _caseService.MyCases(UserPrincipal.User.LoginID).ConfigureAwait(false);
                    var model = _mapper.Map<CaseViewListVm>(result.Data);
                    return PartialView("~/Views/CaseView/_CaseView.cshtml", model);
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
    }
    here the automapper config class i am injecting

    Code:
    public static class AutoMapperConfig 
        {
            public static IMapper CreateMapperConfig()
            {
                var mappingConfig = new MapperConfiguration(mc =>
                {
                    mc.AddProfile(new AutoMapperMapping());
                });
    
                IMapper mapper = mappingConfig.CreateMapper();
                return mapper;
            }
        }
    Code:
    public class AutoMapperMapping : Profile
        {
            public AutoMapperMapping()
            {
                CreateMap<CaseViewListVm, CaseViewListDto>();
                CreateMap<CaseViewListDto, CaseViewListVm>();
             }
       }
    Last edited by NeedSomeAnswers; Oct 2nd, 2020 at 03:38 AM.
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  8. #8
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: MVC Core Lessons

    Hi DDay,

    did the code i posted make sense in terms of your project? let me know.

    happy to talk it over or provide some more code samples.
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width