Skip to content

Instantly share code, notes, and snippets.

View CoreProgramm's full-sized avatar
🎯
Focusing

CoreProgramm CoreProgramm

🎯
Focusing
View GitHub Profile
@CoreProgramm
CoreProgramm / ConfigureServices.cs
Created May 8, 2020 12:07
Difference between AddMvc() and AddMvcCore()
public void ConfigureServices(IServiceCollection services)
{
var builder = services.AddMvcCore();
builder.AddJsonFormatters();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
@CoreProgramm
CoreProgramm / HomeController.cs
Created May 8, 2020 11:26
Difference between AddMVC() and AddMvc() Core
public class HomeController : Controller
{
public JsonResult Index()
{
return Json(new { Name = "John Smith", Country = "USA", Designation = "Software Engineer" });
}
}
@CoreProgramm
CoreProgramm / HomeController.cs
Created May 7, 2020 15:33
Setup MVC in ASP .NET Core
public class HomeController : Controller
{
public string Index()
{
return "Hello from MVC | Coreprogram";
}
}
@CoreProgramm
CoreProgramm / Startup.cs
Created May 7, 2020 15:28
Setup MVC Application
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
@CoreProgramm
CoreProgramm / Startup.cs
Last active May 11, 2020 19:40
Setup MVC Application
public void ConfigureServices(IServiceCollection services)
{
// If you are using .NET Core SDK 2.2
services.AddMvc();
// OR If you are using .NET Core 3.0 or 3.1 then you need to customize the AddMVC() like this.
services.AddMvc(options => options.EnableEndpointRouting = false);
}
@CoreProgramm
CoreProgramm / CustomerController.cs
Created May 6, 2020 20:30
Introduction to .NET Core MVC Framework
public class CustomerController : Controller
{
private CustomerRepository _customerRepository;
public CustomerController(ICustomerRepository customerRepository)
{
_customerRepository = customerRepository;
}
public IActionResult Details(int id)
@CoreProgramm
CoreProgramm / Customer.html
Last active May 6, 2020 20:25
Introduction to .NET Framework MVC
@model CustomerManagement.Customer
<html>
<head>
<title>Customer Details</title>
</head>
<body>
<table class="has-fixed-layout" style="width:50%">
<thead>
<tr><th colspan="2">Customer Details</th></tr>
</thead>
@CoreProgramm
CoreProgramm / Customer.cs
Created May 6, 2020 19:55
Introduction to ASP.NET MVC
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Mobile { get; set; }
}
public interface ICustomerRepository
{
@CoreProgramm
CoreProgramm / configure.cs
Created May 2, 2020 16:27
Environment Variables
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// If the environment is Development serve Developer Exception Page
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
// else serve User Friendly Error Page with Application Support Contact Info
public async Task Invoke(HttpContext httpContext)
{
await httpContext.Response.Body.WriteAsync(Encoding.ASCII.GetBytes("Called from Custom Middleware -- "));
await _next.Invoke(httpContext);
}