Sample project using .Net core 3.1 and MVC template. Academic sample
We will using MVC and Web Api template to learn the base concepts about Net Core had been built. Moreover we will try to implement some razor views and html views searching compare the ways to create web applications.
We'll use boopstrap 4 framework to build responsive views and vanilla Javascript to interact with DOM
To get base boopstrap template, please click Here.
We'll use dotnet core 3.1 to create different projects to match concepts between available projects on visual studio wizard.
Moreover, we'll need a any database engine and we'll EntityFrameworkCore to improve our approach.
So, For this sample I will use MySql (Click to Download)
Note: You can use wherever DB engine, feel like free!
Remember: You must install all dependencies for net core. Like this
- Create a dot net core 3.1 project using visual studio 2019
- How To build a project on VS
- EntityFrameworCore (Code first approach)
- Create Context
- Build a MVC Prject and explain essencial functionality
- Add Javascript functionality
- Repository Pattern
- Refactor using Repos
- Build a Web API project
- To be continue...
- Nuget dependencies:
- Microsoft.EntityFrameworkCore
- Microsoft.EntityFrameworkCore.Tools
- MySql.Data.EntityFrameworkCore
- Microsoft.EntityFrameworkCore.SqlServer
- Microsoft.AspNetCore.Mvc.NewtonsoftJson
- System.IdentityModel.Tokens.Jwt
- Microsoft.AspNetCore.Authentication.JwtBearer
- Connection String: "ConnectionStrings": { "DefaultConnection": "server=localhost;port=3306;user=root;password=Diego1.;database=net_core_sample"}
- Add Context: services.AddDbContext(options => options.UseMySQL(this.Configuration.GetConnectionString("DefaultConnection")));
- Resolve Json Responses: services.AddMvc() .AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver()) .AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore) .AddNewtonsoftJson(options => options.SerializerSettings.DateFormatHandling = DateFormatHandling.MicrosoftDateFormat) .AddNewtonsoftJson(options => options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc);
- To Set JWT config services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters() { ValidateIssuer = true, ValidateAudience = true, ValidAudience = Configuration.GetSection("JwtSettings").GetValue("Audience"), ValidIssuer = Configuration.GetSection("JwtSettings").GetValue("Issuer"), IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration.GetSection("JwtSettings").GetValue("Key"))) }; });
-
Nuget Manage Console:
- Fist Time --> Add-Migration Initial
- Update Database --> Update-Database (Update last Migration)
- More times --> Add-Migration [PutHereChangeName]
- Drop Database --> Drop-Database
- Remove last Migration --> Remove-Migration
Many thanks,
Just do it! - Enjoy the play!