Outline
- ASP.NET Web API with Victor Campos
- Setting Up The Solution
- NuGet Package Manager
-
Authentication and Authorization - Registration Part 1
- Introduction
- Security
- Creating The Users Controller
- Exercise - Create Controllers
- Solution - Create Controllers
- Generics
- Create Generic Class
- Create Register Request
- Create User Response
- Create Register User Endpoint
- Interfaces
- Extracting Interfaces
- Injecting Account Repository
- Dependency Injection
- Implementing Dependency Injection
- 400 vs 422
- Modify Model Validation Behavior
-
Authentication and Authorization - Registration Part 2
- DB Context
- Add Person Domain
- Add Account Domain
- Add DB Context
- Add Connection String
- Configure Dependency Injection for DB Context
- Initial Data Migrations
- Async Process
- Implement Async Process
- Extension Methods
- Implement Extension Methods
- Cryptography
- Implement Password Encryption
- Complete Create Account
- Exercise - Install Auto Mapper
- Solution - Install Auto Mapper
- Configure Auto Mapper
- Exercise - Install JWT Bearer
- Solution - Install JWT Bearer
- Configure JWT
- Exercise - Add Configuration DI
- Solution - Add Configuration DI
- Exercise - Auto Mapper DI
- Solution - Auto Mapper DI
- Implement Create User
- Implement Create Token
- Test Register API Endpoint
- Authentication and Authorization - Login
-
Current User
- Introduction
- Exercise - Invalid Credentials Exception
- Solution - Invalid Credentials Exception
- Exercise - IAccountRepository Add Method Signatures
- Solution - IAccountRepository Add Method Signatures
- Exercise - AccountRepository Implement Interface
- Solution - AccountRepository Implement Interface
- Exercise - IAccountRepository Dependency Injection
- Solution - IAccountRepository Dependency Injection
- Exercise - Add CurrentUserAsync
- Solution - Add CurrentUserAsync
- Overview ASP.NET Core Authentication
- Configure Authentication
- Configure OpenAPI
- Implement Swagger Authorization
- Overview HttpContext
- HttpContext Dependency Injection
- Implement GetLoggedInUser
- Test CurrentUser API Endpoint
- Summary
-
Update User
- Introduction
- Exercise - Exception Classes
- Solution - Exception Classes
- Exercise - Implement Interface
- Solution - Implement Interface
- Exercise - UpdateUserAsync
- Solution - UpdateUserAsync
- Exercise - Implement UpdateLoggedInUserAsync
- Solution - Implement UpdateLoggedInUserAsync
- Test UpdateUser API Endpoint
- Summary
-
User Profile
- Introduction
- Exercise - Add Followers
- Solution - Add Followers
- Follows Data Migration
- Exercise - Add Models And Exceptions
- Solution - Add Models And Exceptions
- Exercise - Create Profile Repository
- Solution - Create Profile Repository
- Exercise - Modify ProfilesController
- Solution - Modify ProfilesController
- Implement GetProfileAsync
- Implement GetUserProfileAsync
- Exercise - Follow And Unfollow
- Solution - Follow And Unfollow
- Implement Follow And Unfollow
- Test Follow And Unfollow
- Summary
-
Articles Part 1
- Introduction
- Exercise - Modify Conduit Context
- Solution - Modify Conduit Context Part 1
- Solution - Modify Conduit Context Part 2
- Solution - Modify Conduit Context Part 3
- Solution - Modify Conduit Context Part 4
- Exercise - Create Custom Models
- Solution - Create Custom Models
- API Routes With Variables
- Exercise - Articles API Endpoints
- Solution - Articles API Endpoints
- Exercise - Articles Repository
- Solution - Articles Repository
- Implement Articles Controller
- Exercise - Implement Articles Controller
- Solution - Implement Articles Controller
-
Articles Part 2
- Recap Visualizing The Layers
- Implement Articles Repository Part 1
- Implement Articles Repository Part 2
- Solution - Implement Articles Repository
- Test GetArticles API Endpoint
- Articles Feed
- Articles By Slug
- Create Article
- Debugging
- Update Article
- Include Article Tags Using Linq
- Delete Article
- Add Comments to Article
- Solution - Add Comments To Article
- Get Comments For Article
- Delete Comment From Article
- Favorite And Unfavorite Article
- Tags
Outline
- ASP.NET Web API with Victor Campos
- Setting Up The Solution
- NuGet Package Manager
-
Authentication and Authorization - Registration Part 1
- Introduction
- Security
- Creating The Users Controller
- Exercise - Create Controllers
- Solution - Create Controllers
- Generics
- Create Generic Class
- Create Register Request
- Create User Response
- Create Register User Endpoint
- Interfaces
- Extracting Interfaces
- Injecting Account Repository
- Dependency Injection
- Implementing Dependency Injection
- 400 vs 422
- Modify Model Validation Behavior
-
Authentication and Authorization - Registration Part 2
- DB Context
- Add Person Domain
- Add Account Domain
- Add DB Context
- Add Connection String
- Configure Dependency Injection for DB Context
- Initial Data Migrations
- Async Process
- Implement Async Process
- Extension Methods
- Implement Extension Methods
- Cryptography
- Implement Password Encryption
- Complete Create Account
- Exercise - Install Auto Mapper
- Solution - Install Auto Mapper
- Configure Auto Mapper
- Exercise - Install JWT Bearer
- Solution - Install JWT Bearer
- Configure JWT
- Exercise - Add Configuration DI
- Solution - Add Configuration DI
- Exercise - Auto Mapper DI
- Solution - Auto Mapper DI
- Implement Create User
- Implement Create Token
- Test Register API Endpoint
- Authentication and Authorization - Login
-
Current User
- Introduction
- Exercise - Invalid Credentials Exception
- Solution - Invalid Credentials Exception
- Exercise - IAccountRepository Add Method Signatures
- Solution - IAccountRepository Add Method Signatures
- Exercise - AccountRepository Implement Interface
- Solution - AccountRepository Implement Interface
- Exercise - IAccountRepository Dependency Injection
- Solution - IAccountRepository Dependency Injection
- Exercise - Add CurrentUserAsync
- Solution - Add CurrentUserAsync
- Overview ASP.NET Core Authentication
- Configure Authentication
- Configure OpenAPI
- Implement Swagger Authorization
- Overview HttpContext
- HttpContext Dependency Injection
- Implement GetLoggedInUser
- Test CurrentUser API Endpoint
- Summary
-
Update User
- Introduction
- Exercise - Exception Classes
- Solution - Exception Classes
- Exercise - Implement Interface
- Solution - Implement Interface
- Exercise - UpdateUserAsync
- Solution - UpdateUserAsync
- Exercise - Implement UpdateLoggedInUserAsync
- Solution - Implement UpdateLoggedInUserAsync
- Test UpdateUser API Endpoint
- Summary
-
User Profile
- Introduction
- Exercise - Add Followers
- Solution - Add Followers
- Follows Data Migration
- Exercise - Add Models And Exceptions
- Solution - Add Models And Exceptions
- Exercise - Create Profile Repository
- Solution - Create Profile Repository
- Exercise - Modify ProfilesController
- Solution - Modify ProfilesController
- Implement GetProfileAsync
- Implement GetUserProfileAsync
- Exercise - Follow And Unfollow
- Solution - Follow And Unfollow
- Implement Follow And Unfollow
- Test Follow And Unfollow
- Summary
-
Articles Part 1
- Introduction
- Exercise - Modify Conduit Context
- Solution - Modify Conduit Context Part 1
- Solution - Modify Conduit Context Part 2
- Solution - Modify Conduit Context Part 3
- Solution - Modify Conduit Context Part 4
- Exercise - Create Custom Models
- Solution - Create Custom Models
- API Routes With Variables
- Exercise - Articles API Endpoints
- Solution - Articles API Endpoints
- Exercise - Articles Repository
- Solution - Articles Repository
- Implement Articles Controller
- Exercise - Implement Articles Controller
- Solution - Implement Articles Controller
-
Articles Part 2
- Recap Visualizing The Layers
- Implement Articles Repository Part 1
- Implement Articles Repository Part 2
- Solution - Implement Articles Repository
- Test GetArticles API Endpoint
- Articles Feed
- Articles By Slug
- Create Article
- Debugging
- Update Article
- Include Article Tags Using Linq
- Delete Article
- Add Comments to Article
- Solution - Add Comments To Article
- Get Comments For Article
- Delete Comment From Article
- Favorite And Unfavorite Article
- Tags
Overview
We’ll be taking a look at the application from a aerial view. It’s simply to get an overall understanding of the structure. We’ll also go over the technology, the frameworks and the patterns we’ll be implementing.
Things like:
- Database - for data persistence
- Entity Framework - Object Relational Mapper
- Repository Pattern - An abstraction layer that sits between the client and the data.
- Dependency Injection (Ioc) - A technique used for having dependent objects injected during instantiation.
- ASP.NET Core Web API - What makes the magic of Restful API EndPoints work correctly.
- Generics - Just another method implemented by C# that allows us to reuse code by allowing the use of any data type.
Database
The database is where your data will be persisted. The tables we’ll create thru Data Migrations are:
- Accounts
- People
- Follows
- Editorials
- Favorites
- Tags
- Commentaries
Login accounts
We can’t secure an application without having accounts. We’ll learn how to securely store account information using encryption that is built right into .NET Core.
Profiles
Having the ability to separate the Person data from the accounts is key when it comes to hardening an application to protect it from unwanted intrusion. We’ll learn how to create a link between Accounts and Person’s Profiles to easily access the information for the logged in user without directly accessing persisted account information.
Articles
Articles or Editorials as I’ve called them here, is the bread & butter of the application. This is what drives traffic to a social site like Conduit. People come to read what others have to say.
Comments
This will allow other registered users to comment on Articles. It’s what keeps the conversation going in an Article.
Following
Once you find an interesting Person chances are you have found an Author that you like. Having the ability to follow the work that someone creates is key to bringing users back to your site and making it easy for them to find what is interesting.
Tagging
Having the ability to tag an article will make it easy for others to find things that peak their interest.
Favoriting
Just like bookmarking a page Favoriting an article keeps it handy and easy to find for future reference. Having a visual representation of the data structure will help understand the code that we’ll be writing.
Just think, we’ll never touch the database. All this will be created right from the very C# code we write together!
If you want a copy of this diagram I’ve included a shared link. Copy it to own drive and open it with Diagrams.net Project.
Object Relational Mapping (ORM)
The ORM that we’ll use to map the data is called Entity Framework. Using ADO.NET to access databases comes with its share of caveats. It can be prone to memory leaks if not used correctly. The notion of wrapping ADO.NET in an easy to use framework appeared on February 13, 2002.
As with any version 1.0 it’s never perfect. Entity Framework is no exception to that rule. However, throughout the years Entity Framework has gone through several iterations of improvement. The latest version allows you to abstract the logic of accessing the database. This allows you to easily change the database without modifying any other code in your application. I have to admit that this latest version has really raised the eye brow of many developers - including mine!
The Repository Pattern
This pattern is very well documented by one of my favorite software Developers by the name of Martin Fowler. The whole point of the Repository is to query the database, in our case we’ll ask the ORM to query the database. We might find ourselves querying results from several tables in the database. However, our final result may be a consolidated view model that the Front End requires. A repository performs the tasks of an intermediary between the domain model layers and data mapping, acting in a similar way to a set of domain objects in memory. Client objects declaratively build queries and send them to the repositories for answers. Conceptually, a repository encapsulates a set of objects stored in the database and operations that can be performed on them, providing a way that is closer to the persistence layer. Repositories, also, support the purpose of separating, clearly and in one direction, the dependency between the work domain and the data allocation or mapping.
Basically, it’s another layer of abstraction that bridges the logic between a client and the data. As we start writing the code you’ll easily identify the repository.
The Web API Controller
For every request, this is where the heavy lifting occurs. ASP.NET Core Web API Framework started as an open source project and to this day still is. The only difference is that the .NET Core Team has baked it in as part of the Common Libraries.
ASP.NET Core Built-In Middleware
ASP.NET Core Middleware that comes built-in contains code that every application needs to deal with:
- Authentication & Authorization
- Managing User Sessions
- Controller Routing
- Swagger API Document Implementation
Along with many other “boiler-plate” code, patterns and implementations.
Just imagine that all the spices and side dishes are included. We get to focus on the “meat & potatoes” of the application.
Dependency Injection
Another well documented technique widely used in OOP. It’s a form of the broader technique called Inversion of Control. An object should not have to know how to construct a dependency. Instead it should delegate the job the injector. Dependent object are not allowed to call the injector. The injector is responsible for creating the chain of dependent objects.