Building Microservices with ASP.NET Core

Book description

At a time when nearly every vertical, regardless of domain, seems to need software running in the cloud to make money, microservices provide the agility and drastically reduced time to market you require. This hands-on guide shows you how to create, test, compile, and deploy microservices, using the ASP.NET Core free and open-source framework. Along the way, you’ll pick up good, practical habits for building powerful and robust services.

Building microservices isn’t about learning a specific framework or programming language; it’s about building applications that thrive in elastically scaling environments that don't have host affinity, and that can start and stop at a moment’s notice. This practical book guides you through the process.

  • Learn test-driven and API-first development concepts
  • Communicate with other services by creating and consuming backing services such as databases and queues
  • Build a microservice that depends on an external data source
  • Learn about event sourcing, the event-centric approach to persistence
  • Use ASP.NET Core to build web applications designed to thrive in the cloud
  • Build a service that consumes, or is consumed by, other services
  • Create services and applications that accept external configuration
  • Explore ways to secure ASP.NET Core microservices and applications

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. What You’ll Build
    2. Why You’re Building Services
    3. What You’ll Need to Build Services
    4. Online Resources
    5. Conventions Used in This Book
    6. Using Code Examples
    7. O’Reilly Safari
    8. How to Contact Us
    9. Acknowledgments
  2. 1. ASP.NET Core Primer
    1. Distilling the Core
      1. CoreCLR
      2. CoreFX
      3. .NET Platform Standard
      4. ASP.NET Core
    2. Installing .NET Core
    3. Building a Console App
    4. Building Your First ASP.NET Core App
      1. Adding ASP.NET Packages to the Project
      2. Adding the Kestrel Server
      3. Adding a Startup Class and Middleware
      4. Running the App
    5. Summary
  3. 2. Delivering Continuously
    1. Introducing Docker
      1. Installing Docker
      2. Running Docker Images
    2. Continuous Integration with Wercker
    3. Building Services with Wercker
      1. Installing the Wercker CLI
      2. Adding the wercker.yml Configuration File
      3. Running a Wercker Build
    4. Continuous Integration with CircleCI
    5. Deploying to Docker Hub
    6. Summary
  4. 3. Building a Microservice with ASP.NET Core
    1. Microservices Defined
    2. Introducing the Team Service
    3. API First Development
      1. Why API First?
      2. The Team Service API
    4. Test-First Controller Development
      1. Injecting a Mock Repository
      2. Completing the Unit Test Suite
    5. Creating a CI Pipeline
    6. Integration Testing
    7. Running the Team Service Docker Image
    8. Summary
  5. 4. Backing Services
    1. Microservice Ecosystems
      1. Bound Resources
      2. Strategies for Sharing Models Between Services
    2. Building the Location Service
    3. Enhancing the Team Service
      1. Configuring Service URLs with Environment Variables
      2. Consuming a RESTful Service
      3. Running the Services
    4. Summary
  6. 5. Creating a Data Service
    1. Choosing a Data Store
    2. Building a Postgres Repository
      1. Creating a Database Context
      2. Implementing the Location Record Repository Interface
      3. Testing with the Entity Framework Core In-Memory Provider
    3. Databases Are Backing Services
      1. Configuring a Postgres Database Context
    4. Integration Testing Real Repositories
    5. Exercising the Data Service
    6. Summary
  7. 6. Event Sourcing and CQRS
    1. Introducing Event Sourcing
      1. Reality Is Event Sourced
      2. Event Sourcing Defined
      3. Learning to Love Eventual Consistency
    2. The CQRS Pattern
    3. Event Sourcing and CQRS in Action—Team Proximity Sample
      1. The Location Reporter Service
      2. The Event Processor
      3. The Reality Service
      4. The Proximity Monitor
    4. Running the Samples
      1. Starting the Services
      2. Submitting Sample Data
    5. Summary
  8. 7. Building an ASP.NET Core Web Application
    1. ASP.NET Core Basics
      1. Adding ASP.NET MVC Middleware
      2. Adding a Controller
      3. Adding a Model
      4. Adding a View
      5. Invoking REST APIs from JavaScript
    2. Building Cloud-Native Web Applications
      1. API First
      2. Configuration
      3. Logging
      4. Session State
      5. Data Protection
      6. Backing Services
      7. Environment Parity
      8. Port Binding
      9. Telemetry
      10. Authentication and Authorization
    3. Summary
  9. 8. Service Discovery
    1. Refresher on Cloud-Native Factors
      1. External Configuration
      2. Backing Services
    2. Introducing Netflix Eureka
    3. Discovering and Advertising ASP.NET Core Services
      1. Registering a Service
      2. Discovering and Consuming Services
    4. DNS and Platform Supported Discovery
    5. Summary
  10. 9. Configuring Microservice Ecosystems
    1. Using Environment Variables with Docker
    2. Using Spring Cloud Config Server
    3. Configuring Microservices with etcd
      1. Creating an etcd Configuration Provider
    4. Summary
  11. 10. Securing Applications and Microservices
    1. Security in the Cloud
      1. Intranet Applications
      2. Cookie and Forms Authentication
      3. Encryption for Apps in the Cloud
      4. Bearer Tokens
    2. Securing ASP.NET Core Web Apps
      1. OpenID Connect Primer
      2. Securing an ASP.NET Core App with OIDC
      3. OIDC Middleware and Cloud Native
    3. Securing ASP.NET Core Microservices
      1. Securing a Service with the Full OIDC Security Flow
      2. Securing a Service with Client Credentials
      3. Securing a Service with Bearer Tokens
    4. Summary
  12. 11. Building Real-Time Apps and Services
    1. Real-Time Applications Defined
    2. Websockets in the Cloud
      1. The WebSocket Protocol
      2. Deployment Models
    3. Using a Cloud Messaging Provider
    4. Building the Proximity Monitor
      1. Creating a Proximity Monitor Service
      2. Creating a Real-Time Proximity Monitor UI
    5. Summary
  13. 12. Putting It All Together
    1. Identifying and Fixing Anti-Patterns
      1. Cleaning Up the Team Monitor Sample
    2. Continuing the Debate over Composite Microservices
      1. Mitigating Risk with Circuit Breakers
      2. Eliminating the Synchronous Composite Pattern
    3. What Next?
  14. Index

Product information

  • Title: Building Microservices with ASP.NET Core
  • Author(s): Kevin Hoffman
  • Release date: September 2017
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491961735