Saturday, November 19, 2022

asp.net middleware extension methods

  •  UseDevelopeerExceptionPage
    • Captures synchronous and asynchronous System.Exception instances from the pipeline and generates HTML error responses.
  • UseHsts
    • Adds middleware for using HSTS, which adds the Strict-Transport-Security header.
  • UseRouting
    • Adds middleware that defines a point in the pipeline where routing decisions are made and must be combined with a call to UseEndpoints where the processing is then executed. This means that for our code, any URL paths that match / or /index or /page will be mapped to Razor Pages and match on /hello will be mapped to the anonymous delegate. Any other URL paths will be passed on to the next delegate for matching, for example, static files. This is why, although it looks like the mapping for Razor Pages and /hello happen after static files in the pipeline, they actually take priority because the call to UseRouting happens before UseStaticFiles.
  • UseHttpsRedirection
    • Adds middleware for redirecting HTTPS requests to HTTPS, so in our code request for htttp://lcocalhost:5000 would be modified to https://localhost:5001
  • UseDefaultFiles
    • Adds middleware that enables default file mapping on the current path, so in our code it would identify files such as index.html
  • UseStaticFiles
    • Adds middleware that looks in wwwroot for static files to return in the HTTP response.
  • UseEndpoints
    • Adds middleware to execute to generate response from decision made earlier in the pipeline. Two endpoints are added, as shown in the following sub-list.
      • MapRazorPages
        • Adds middleware that will map URL paths such as /suppliers to Razor Page file in the /Pages folder named suppliers.cshtml and return the result as the HTTP response.
      • MapGet
        • Adds middleware that will map URL paths such as /hello to an inline delegate writes plain test directly to the HTTP response.

run, map and use methods in asp.net

 Run

Adds a middleware delegate that determinates the pipeline by immediately returning a response instead of calling the next middleware delegate.

Map

Adds a middleware delegate that creates a branch in the pipeline when there is a matching request usually based on a URL path like /hello


Use

Adds a middleware delegate that forms part of the pipeline so it can decide if it wants to pass the request to the next delegate in the pipeline and it can modify the request and response before and after the next delegate.


Registering services in the ConfigureServices method

AddMvcCore
minimum set of services to route and invoke controller. most websites will need more configuration than this.

AddAuthorization
authentication and authorization services.

AddDataAnnotations
mvc data annotations service.

AddCacheTagHelper
mvc cache tag helper service

AddRazorPages
razor pages service includes the razor view engine. commonly used in simple website projects. it calls the following additional methods.
  • AddMvcCore
  • AddAuthorization
  • AddDataAnnotations
  • AddCacheTagHelper
  • AddApiExplorer
  • AddCors
  • AddFormaterMappings
AddViews
support for .cshtml views including default conventions.

AddRazorViewEngine
support for razor view engine including proessing the @symbol.

AddControllerWithViews
controller, views, and pages services. commonly used in ASP.NET Core MVC projects. it calls the following additional methods.
  • AddMvcCore
  • AddAuthorization
  • AddDataAnnotations
  • AddCacheTagHelper
  • AddApiExplorer
  • AddCors
  • AddFormattermappings
  • AddViews
  • AddRazorViewEngine
AddMvc
similar to AddControllerWithViews, but you should only use it for backward compatibility.

AddContext<T>
your DbContext type and its optional DbContextOptions<TContext>

AddCustomContext
a custom extension method we created to make it easier to register the NorthwindContext class for either SQLite or SQL Server based on the project referenced.





Friday, November 18, 2022

The Object Oriented Thought Process 5th Edition

Object Wrappers
object wrappers are object-oriented code that includes other code inside for example. you can take structured code (such as loops and conditions) and wrap it inside an object to make it look like an object. You can also use object wrappers to wrap functionality such as security features, nonportable hardware features, and so on.


sound class design guidelines
keep in mind that it is possible to create poorly designed oo classes that do not restrict access to class attributes. The bottom line is that you can design bad code just as efficiently with oo design as with any other programming methodology.

in general, objects should not manipulate the internal data of other objects.


Wednesday, November 9, 2022

How to pass data to parent in vue.js

 
This is how we can pass data from child to parent component in vue js.

  1. child component should emit a custom event which pass data.
  2. parent component should listen for it via v-on

Tuesday, November 8, 2022

How to install and initialize vue js?

INSTALLING VUE JS

  1. Using Scripts
    1. Development Scripts
    2. Production Scripts
  2. CLI
    1. npm
      1. npm install --global @vue/cli
    2. yarn
      1.  yarn global add @vue/cli

How to create database context class and adding tables to it? ASP.NET Core 6

CODE:

namespace projectnamespace;
public class Northwind : DbContext { 
var DataProvider="SQLite";
 
 protected override void OnConfiguring( DbContextOptionsBuilder     optionsBuilder) { 
 if (DatabaseProvider == "SQLite") { 
     string path = Path.Combine( Environment.CurrentDirectory, "Northwind.db"); 
 WriteLine($"Using {path} database file."); 

 optionsBuilder.UseSqlite($"Filename={path}"); 
 } else { 
     string connection = "Data Source=.;" + "Initial Catalog=Northwind;" + "Integrated Security=true;" + "MultipleActiveResultSets=true;";

     optionsBuilder.UseSqlServer(connection);
 } 
  public DbSet? Table1{ get; set; } 
  public DbSet? Table2{ get; set; }
}

Saturday, November 5, 2022

ASP.NET6 command to scafold modules using an existing database

NOTE : Make sure Microsoft.EntityFrameworkCore.Design package should be added to your project.

dotnet ef dbcontext scaffold "Filename=dbname.db" Microsoft. EntityFrameworkCore.Sqlite --table tablename --table tablename --outputdir Foldername --namespace Namespace --data-annotations --context Dbcontext

Note the following:


• The command action: dbcontext scaffold
• The connection string: "Filename=Northwind.db" 
• The database provider: Microsoft.EntityFrameworkCore.Sqlite 
• The tables to generate models for: --table Categories --table Products 
• The output folder: --output-dir AutoGenModels 
• The namespace: --namespace WorkingWithEFCore.AutoGen 
• To use data annotations as well as the Fluent API: --data-annotations 
• To rename the context from [database_name]Context: --context Northwind

asp.net core connection string for all databases in detail.

SQLITE

To make an SQLite database connection string, we just need to know the databse filename, set using the paramenter Filename.

Steps :


SQL Server

To connect to an SQL Server database, we need to know all these pieces of informations given.

  • Server name
  • Database name
  • Security informations such as username & password or if we pass the currently logged-on user's credentials automatically.
    We specify this information in a connection string

Steps :

Wednesday, November 2, 2022

How to use vue with dotnet6 ?

 Follow these steps to use Vue with asp.net core.


1. Go To- https://dotnetnew.azurewebsites.net/

2. Search for Vue and select one template

3. Click on- go to project

4. Clone or download the repository

5. Run the command.



methods available in Dapper

  Dapper is a micro ORM library for .NET and .NET Core applications that allows you to execute SQL queries and map the results to objects. D...