Skip to main content

Posts

Showing posts with the label Dotnet Core

A CRUD Operation Demo With Blazor WebAssembly(.NET6) + Strawberry Shake GraphQL Client + MudBlazor UI + GraphQL API

In this article, we are to implement CRUD operation in Blazor WebAssembly(.NET6) by consuming GraphQL endpoint with help of  'Strawberry Shake'(Graphql Client Library). GraphQL Endpoint: In this demo, we have to consume the GraphQL endpoint from our Blazor WebAssembly application. Source code for .Net6 GraphQL CRUD operations. The article explains about creating .NET 6 GraphQL CRUD operations The video explains about creating .NET6 GraphQL CRUD operations Strawberry Shake: Strawberry shake is an open-source GraphQL client that is compliant with the newest GraphQL draft spec, which makes Strawberry Shake compatible with all GraphQL compliant servers like Hot Chocolate, Apollo Server, GraphQL Java, and various other servers out there. Strawberry Shake will generate the schema of GraphQL Server which will help to invoke the GraphQL endpoint very easily. Strawberry Shake CLI Tool: Strawberry shake CLI needs to be configured because CLI will help us to generate the GraphQL clie

A Basic GraphQL CRUD Operation With .NET6 + Hot Chocolate(V 12) + SQL Database

In this article, we are going to implement GraphQL CRUD operation in .NET6, Hot Chocolate(V12), SQL Database. GraphQL: GraphQL is an open-source data query and manipulation and language for APIs. It is a query language for your API and a server-side runtime for executing queries by using a type system you define for your data. GraphQL can be integrated into any framework like .NET, Java, NestJS, etc and it isn't tied to any specific database or storage engine and is backed by your existing code and data. GraphQL 2 main operations are like: Query(fetching data) Mutation(data manipulation like save, update, delete) Hot Chocolate GraphQL: Hot Chocolate is an open-source GraphQL server that is compliant with the newest GraphQL latest specs. It is the wrapper library of the original .NET GraphQL library. Hot Chocolate takes the complexity away from building a fully-fledged GraphQL server. Create A .NET6 Web API Project: Let's create a .Net6 Web API sample application to accompli

Hot Chocolate GraphQL Pagination Using Cursor Technique[.NET 6]

In this article, we are going to understand the Cursor Pagination technique in Hot Chocolate GraphQL. GraphQL Cursor Paging: In GraphQL we have cursor-based pagination. The cursors are opaque, either offset or ID-based pagination can be implemented. In the cursor-base pagination based on request Graphql query response return 'Edges', 'PageInfo'(object). Edges consist of an array of objects with properties like 'node', 'cursor'. So 'node' property holds single record data into it. 'cursor' is a base64 string that can be either made by the row number or record primary key id value. So each 'edge' contains 'node'(contains single record data) along with 'cursor', so using the 'cursor' value we can query our server to return the records either before or after the 'cursor' value. PageInfo consist of  'hasNextPage', 'hasPreviousPage', 'startCursor', 'endCursor'. Sample Query

Part-3 Blazor Server Cookie Authentication

In this article, we are going to implement a 'User Login Page' in our Blazor Server application. In this part of the article, we have to accomplish our targets like: Login User Form. Login Authentication Logic. Configuring Cookie Authentication Service. Installing Blazor Authorization Package 'Microsoft.AspNetCore.Components.Authorization'. Adding the 'CascadingAuthenticationState' component. Using the 'AuthorizeView' component. Login Password Validation: Let's add logic to validate the user entered password in the login form against the user hash password stored in the database. Logic/AccountLogic: private bool ValidatePasswordHash(string password, string dbPassword) { byte[] dbPasswordHashBytes = Convert.FromBase64String(dbPassword); byte[] salt = new byte[16]; Array.Copy(dbPasswordHashBytes, 0, salt, 0, 16); var userPasswordBytes = new Rfc2898DeriveBytes(password, salt, 1000); byte[] userPasswordHash = userPasswordBytes.GetBytes(20);

.NET6 Razor Pages CRUD Operations With Entity Framework Core

In this article, we will do a small demo of the AspNetCore 6 Razor Pages CRUD operation. Razor Pages: Razor Page is a simplified web application model. On comparing with the 'MVC' template, razor pages won't have 'Controller', which means Razor Page is a combination of 'View' and 'Model'. Routing itself is configured within the page or view. A Razor Page mostly contains 2 files like '*.cshtml'(View) and '*.cshtml.cs'(model). Create A .NET6 Razor Pages Application: Let's create a .Net6 Razor Page sample application to accomplish our demo. We can use either Visual Studio 2022 or Visual Studio Code(using .NET CLI commands) to create any.Net6 application. For this demo, I'm using the 'Visual Studio Code'(using the .NET CLI command) editor. CLI command dotnet new webapp -o Your_Project_Name Let's explore the project to understand its structure: (1) Let's understand the initial services registered in 'Progr