Skip to content

Instantly share code, notes, and snippets.

View anjankant's full-sized avatar
🎯
Focusing

Anjan Kant anjankant

🎯
Focusing
View GitHub Profile
@anjankant
anjankant / Net-Core-Features-Host
Created November 28, 2022 10:45
.Net Core Features - Host
var builder = WebApplication.CreateBuilder(args); // Add service
container.builder.Services.AddRazorPages();
builder.Services.AddControllersWithViews();
var app = builder.Build();
@anjankant
anjankant / Net-Core-Features-Middleware.txt
Last active November 28, 2022 10:32
.Net Core Features - Middleware
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.Use(async (context, next) =>
{
// Do work that can write to the Response.
await next.Invoke();
// Do logging or other work that doesn't write to the Response.
});
@anjankant
anjankant / Scoped
Created October 12, 2022 17:58
Scoped
AddScoped<ITCService, TCService>();
@anjankant
anjankant / Transient
Last active October 12, 2022 18:01
Transient
services.AddTransient<ITCService, TCService>();
@anjankant
anjankant / types-of-life-times
Last active October 12, 2022 18:01
How many types of life times
services.AddSingleton<ITCService, TCService>();
@anjankant
anjankant / inject-service-dependency-into-the-controller-III
Last active October 12, 2022 18:02
inject the service dependency into the controller
public class HomeController: Controller
{
ITCService _TCService;
public HomeController(ITCService _TCService)
{
_TCService = TCService;
}
}
@anjankant
anjankant / inject-service-dependency-into-the-controller-II
Last active October 12, 2022 18:00
inject the service dependency into the controller
public void ConfigureServices(IServiceCollection services)
{
....
.....
services.AddTransient<ITCService, TCService>();
......
......
}
@anjankant
anjankant / inject-service-dependency-into-the-controller
Last active October 12, 2022 18:04
inject the service dependency into the controller
public interface ITCService
{
string SaysTC();
}
public class TCService: ITCService
{
public string SaysTC()
{
return “TC";
@anjankant
anjankant / bind-automatic-model-in-Razor-pages
Created October 12, 2022 17:52
bind the automatic model in Razor pages
public class Test1Model : PageModel
{
[BindProperty]
public string Name { get; set; }
}
@anjankant
anjankant / Razor-Pages-in-NET-Core
Last active October 12, 2022 18:05
Razor Pages in ASP.NET Core
@page
<h1> Welcome!</h1>
<h2> This is my first sample Razor Page :) </h2>