@manhnguyenv

Welcome to my blog!

Googling

January 5, 2018 18:48

Googling all .NET articles

Push Notifications in .NET Core

https://github.com/tpeczek/Demo.AspNetCore.PushNotifications

Real-time in .NET Core:

http://gunnarpeipman.com/2018/01/aspnet-core-windows-iot-websocket/

Token in ASP.NET Core 2.0

https://jonhilton.net/2017/10/11/secure-your-asp.net-core-2.0-api-part-1---issuing-a-jwt/

https://jonhilton.net/security/apis/secure-your-asp.net-core-2.0-api-part-2---jwt-bearer-authentication/

GIT không có gì đáng sợ

https://viblo.asia/p/git-khong-co-gi-dang-so-yMnKMgMQl7P

Design Principles & Patterns

Posted in API, architecture, design, ASP.NET Core, Microsoft Azure, refactoring, software architecture, SOLID principles

Authors

https://amanagrawal.blog/

Bài học về sự kết hợp giữa Cookie-based AuthToken-based Auth trong ứng dụng ASP.NET Core MVC

https://programmingwithmosh.com/

Bài học kinh nghiệm về thiết kế kiến trúc dự án

http://geekswithblogs.net/

https://8thlight.com/

https://dotnetthoughts.net/ (Multi-tenant SaaS database tenancy patterns)

Bài học về design patterns

Blog in ASP.NET Core 2.0

https://github.com/HamidMosalla/FreelancerBlog

Multi tenant web applications

https://amanagrawal.blog/2017/09/11/dynamically-mapping-tenant-requests-to-tenant-databases-in-multi-tenant-web-applications/

Samples

https://github.com/explorer14/JwtAuthenticationHelper

A simple Json Web Token authentication helper library that allows you to generate access tokens easily for both ASP.NET Core web apps (cookie based auth) and Web APIs (stateless token based auth).

ASP.NET MVC Samples

MVC6 - Good Samples

https://github.com/ssshekhawat/ASP.NET-Core-MVC-Example

MVC5 - Good Samples

https://github.com/kristianguevara/MyFirstWebsite-ASP.NET-MVC5

https://xtianguevara.com/creating-your-asp-net-mvc-5-application-from-scratch-for-beginners-using-entity-framework-6-and-identity-with-crud-functionalities/

Requirements

  1. Creating your Empty Project
  2. Creating the Authentication Middleware using Identity
    1. Installing the Owin packages
    2. Coding the Middleware
    3. Connecting the Middleware to the Solution
  3. Creating the Basic Home Pages
    1. Adding the Home Controller
    2. Adding the Home View
    3. Explaining Views and Master Page
  4. Adding Authentication Security and Unauthorized Page Placeholder
  5. Creating the Login Model and Login Form
  6. Adding the Login logic With Hard-coded Values
    1. Adding the HttpGet Login Method
    2. Adding the HttpPost Login Method
    3. Adding Credential Validations
    4. Displaying the Error Message and Adding URL Validation
  7. Displaying Persisted Values and Adding the Logout Logic
    1. Displaying Your Name
    2. Creating the Logout Button and Logic
  8. Creating the Database using LocalDb
    1. Connecting the Database to the App through Connection Strings
    2. Creating the Database Tables
  9. Linking the Database Through Entity Framework
    1. Creating the Context and Renaming the LoginModel
    2. Cleaning our AuthController Redirection
  10. Creating the Registration Page
    1. Creating the Registration Action and View Page
    2. Creating Data Encryption and Decryption
    3. Creating the Query Logic
    4. Editing the Login Logic
  11. Creating our List Table
    1. Creating the UI for the tables
    2. Creating the List Model and Linking it to the Database
    3. Adding Input Fields
    4. Explaining Relationships Between Tables: Another Logged-in User = Different Item List
  12. Adding Items to our List
  13. Displaying the Items to the List
  14. Editing the Items
    1. Adding the Edit View
    2. Creating the Edit Logic
  15. Deleting Items from the List
  16. Displaying Public Data
  17. Cleaning the Code
  18. Debriefing and Summary

Technologies & Tools

  • Visual Studio 2013
  • EntityFramework version 6
  • AspNet.Mvc version 5
  • Owin
  • Owin (Open Web Interface for .NET)

OWIN (Open Web Interface for .NET): chuẩn giao tiếp mở giữa Web Server và Web Application. Lợi ích của OWIN là:

- Cho phép tạo ra các middleware components có thể thay thế hoặc thêm vào trong ứng dụng mà không ảnh hưởng tới các thành phần khác trong ứng dụng đó.

- Loại bỏ việc host ứng dụng chỉ dựa vào web server, đẩy mạnh hơn việc sử dụng self-host.

KATANA: Framework open source của Microsoft thực thi OWIN. Katana cung cấp Katana's self host server, custom host server như console app, windows service để có thể host các middleware như ASP.NET Web API hay SignalR...

Như vậy có thể thấy giờ đây ngoài IIS, chúng ta còn có thể host ứng dụng trên self-host như Katana server, windows service, console app... Đây là một chiến lược của Microsoft trong việc mở rộng .NET đến các nền tảng như Linux, Mac... Và điều này cũng đem lại nhiều thuận lợi hơn cho lập trình viên chúng ta.

  • AspNet.Identity.OWIN: được sử dụng khi bạn thêm hàm login vào hệ thống và gọi OWIN Cookie Authentication middleware để tạo cookie.
  • AspNet.Identity.EntityFramework: dùng để ánh xạ dữ liệu và schema ASP.NET vào SQL Server.
  • Owin.Host.SystemWeb: cho phép server Owin chạy API trên IIS sử dụng ASP.NET request pipeline.
  • AspNet.WebApi.Owin: cho phép bạn lưu trữ ASP.Net Web API trong OWIN Server và cung cấp quyền truy cập các tính năng của OWIN.
  • Owin.Security.Oauth: là 1 Middleware, cho phép ứng dụng hỗ trợ đăng nhập bằng Oauth 2.0.
  • Owin.Cors: chứa những components cho phép thực hiện Cross-Origin Resource Sharing (CORS) trong OWIN middleware (truy cập các resource bên ngoài).

Cài đặt Nuget Packages

Chúng ta sẽ cài đặt Nuget packages để thiết lập Owin server và cấu hình ASPNET Web API để lưu trữ Owin Server.

  • Install-Package Microsoft.AspNet.Identity.Owin
  • Install-Package Microsoft.AspNet.Identity.EntityFramework
  • Install-Package Microsoft.Owin.Host.SystemWeb
  • Install-Package Microsoft.AspNet.WebApi.Owin
  • Install-Package Microsoft.Owin.Security.OAuth
  • Install-Package Microsoft.Owin.Cors

Tham khảo:

http://johnatten.com/2013/10/27/configuring-db-connection-and-code-first-migration-for-identity-accounts-in-asp-net-mvc-5-and-visual-studio-2013/

http://johnatten.com/2013/11/11/extending-identity-accounts-and-implementing-role-based-authentication-in-asp-net-mvc-5/

http://johnatten.com/2013/07/03/building-out-a-clean-rest-ful-web-api-service-with-a-minimal-web-api-project/

OWIN:

http://johnatten.com/2015/01/04/asp-net-understanding-owin-katana-and-the-middleware-pipeline/

Retrieview json result từ Web API thông qua Console Application

iTextSharp: làm việc với Excel

DocX: làm việc với Word

C# LinqToExcel

http://bitoftech.net/2015/01/21/asp-net-identity-2-with-asp-net-web-api-2-accounts-management/

Researching

Encrypt & Decrypt

https://stackoverflow.com/questions/3253325/cryptographic-exception-input-is-not-a-complete-block

HTML special characters

http://htmlhelp.com/reference/html40/entities/special.html

Users and Roles management

https://code.msdn.microsoft.com/ASPNET-MVC-5-Security-And-44cbdb97

Ví dụ có sử dụng Web API và Bootstrap
http://www.c-sharpcorner.com/UploadFile/8a67c0/repository-pattern-and-generic-repository-pattern/
http://www.c-sharpcorner.com/article/generic-repository-pattern-in-asp-net-core/
https://code.msdn.microsoft.com/Generic-Repository-Pattern-f133bca4
https://code.msdn.microsoft.com/generic-repository-pattern-ddea2262

https://www.codeproject.com/Articles/814768/CRUD-Operations-Using-the-Generic-Repository-Patte

ASP.NET Core MVC Example
This repository holds sample application which developed using ASP.NET Core MVC

First Application
Its name is EmployeeApplication. It is developed using ASP.NET Core 2.0. It tutorial is http://l-knowtech.com/2017/08/15/getting-started-asp-net-core-mvc/

CRUD Operations Using Entity Framework Core
Its solution folder name is FirstCRUDApplication. It's tutorial is http://l-knowtech.com/2017/08/28/first-crud-application-asp-net-core-mvc-using-entity-framework-core/

Repository Pattern In ASP.NET Core MVC And Entity Framework Core
Its solution folder name is RepositoryPattern. It's tutorial is http://l-knowtech.com/2017/09/12/repository-pattern-asp-net-core-mvc-entity-framework-core/

Generic Repository Pattern In ASP.NET Core MVC And Entity Framework Core
Its solution folder name is GenericRepository. It's tutorial is http://l-knowtech.com/2017/09/24/generic-repository-pattern-asp-net-core-mvc-entity-framework-core/

https://github.com/ssshekhawat/ASP.NET-Core-MVC-Example


Clean Architecture with .NET
https://github.com/ardalis/CleanArchitecture
Last updated October 2017 for .NET Core 2.0


https://blogs.msdn.microsoft.com/dotnet/2017/08/09/web-apps-aspnetcore-architecture-guidance/
Updated for ASP.NET Core 2.0 (Nov. 15th 2017)
What’s new
The eBook/Guide has been updated to ASP.NET Core 2.0, .NET Standard Library 2.0 and Entity Framework 2.0 and .NET Core 2.0 in general, while referencing to the new code implemented in the updated sample app for ASP.NET Core 2, as well.

+ ASP.NET Core 2.0
+ ASP.NET Identity 2.0
+ .NET Standard Library 2.0
+ Entity Framework 2.0
+ .NET Core 2.0
+ Two Factor Authentication (2FA)
+ Razor Pages is a new features added in ASP.NET Core 2.0

https://github.com/dotnet-architecture/eShopOnContainers
Easy to get started sample reference microservice and container based application. Cross-platform on Linux and Windows Docker Containers, powered by .NET Core 2.0 and Docker engine. Supports Visual Studio 2017, VS for Mac and CLI based environments with Docker CLI, dotnet CLI, VS Code or any other code editor.

https://github.com/dotnet-architecture/eShopOnWeb
Sample ASP.NET Core 2.0 reference application, powered by Microsoft, demonstrating a layered application architecture with monolithic deployment model. Download 130+ page eBook PDF from docs folder.

Layered Architecture in ASP.NET Core Applications
Onion Architecture in ASP.NET Core Applications (Jeffrey Palermo)
Growing Object-Oriented Software
Ports and Adapters Architecture (Hexagonal Architecture)

Generic Repository Pattern in ASP.NET Core

A Visual Studio 2015 project which shows how to perform the create, read, update and delete operations in the ASP.NET Core application using generic repository pattern with Entity Framework Core Code First approach.

https://code.msdn.microsoft.com/Generic-Repository-Pattern-f133bca4

http://www.c-sharpcorner.com/article/generic-repository-pattern-in-asp-net-core/

CRUD with Generic Repository Pattern, Dependency Injection and Unit Of Work

  • CRUD Operations Using the Repository Pattern in MVC
  • CRUD Operations Using the Generic Repository Pattern and Unit of Work in MVC
  • CRUD Operations Using the Generic Repository Pattern and Dependency Injection in MVC

https://code.msdn.microsoft.com/generic-repository-pattern-ddea2262

https://github.com/MuhammadNasirKhanYousafzai/GenericServiceWithRepository

Generic Services will make your life easy as you did not need to implement same functionality again and again. Just write them once and use.

Updated 10/11/2016

Why should not I use the Repository pattern with Entity Framework?

https://softwareengineering.stackexchange.com/questions/180851/why-shouldnt-i-use-the-repository-pattern-with-entity-framework/220126

I don't see any reason for the Repository pattern to not work with Entity Framework. Repository pattern is an abstraction layer you put on your data access layer. Your data access layer can be anything from pure ADO.NET stored procedures to Entity Framework or an XML file.

In large systems, where you have data coming from different sources (database/XML/web service), it is good to have an abstraction layer. The Repository pattern works well in this scenario. I do not believe that Entity Framework is enough abstraction to hide what goes on behind the scenes.

I have used the Repository pattern with Entity Framework as my data access layer method and am yet to face a problem.

Another advantage of abstracting the DbContext with a Repository is unit-testability. You can have your IRepository interface to which has 2 implementations, one (the real Repository) which uses DbContext to talk to the database and the second, FakeRepository which can return in-memory objects/mocked data. This makes your IRepository unit-testable, thus other parts of code which uses IRepository.

public interface IRepository

{

  IEnumerable<CustomerDto> GetCustomers();

}

public EFRepository : IRepository

{

  private YourDbContext db;

  private EFRepository()

  {

    db = new YourDbContext();

  }

  public IEnumerable<CustomerDto> GetCustomers()

  {

    return db.Customers.Select(f=>new CustomerDto { Id=f.Id, Name =f.Name}).ToList();

  }

}

public MockRepository : IRepository

{

  public IEnumerable<CustomerDto> GetCustomers()

  {

    // to do : return a mock list of Customers

    // Or you may even use a mocking framework like Moq

  }

}

Now using DI, you get the implementation

public class SomeService

{

  IRepository repo;

  public SomeService(IRepository repo)

  {

     this.repo = repo;

  } 

  public void SomeMethod()

  {

    //use this.repo as needed

  }   

}

 

Categories

Recent posts