100% found this document useful (4 votes)
42 views

Essential Angular for ASP.NET Core MVC 1st Edition Adam Freeman instant download

The document provides information about the book 'Essential Angular for ASP.NET Core MVC' by Adam Freeman, including its ISBN numbers and copyright details. It outlines the contents of the book, which covers various aspects of integrating Angular with ASP.NET Core MVC, including project setup, data modeling, web services, and application security. Additionally, it lists other related titles available for download on the ebookmeta.com website.

Uploaded by

kleshtohenyl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
42 views

Essential Angular for ASP.NET Core MVC 1st Edition Adam Freeman instant download

The document provides information about the book 'Essential Angular for ASP.NET Core MVC' by Adam Freeman, including its ISBN numbers and copyright details. It outlines the contents of the book, which covers various aspects of integrating Angular with ASP.NET Core MVC, including project setup, data modeling, web services, and application security. Additionally, it lists other related titles available for download on the ebookmeta.com website.

Uploaded by

kleshtohenyl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 70

Essential Angular for ASP.

NET Core MVC 1st


Edition Adam Freeman install download

https://ebookmeta.com/product/essential-angular-for-asp-net-core-
mvc-1st-edition-adam-freeman/

Download more ebook from https://ebookmeta.com


We believe these products will be a great fit for you. Click
the link to download now, or visit ebookmeta.com
to discover even more!

Pro Entity Framework Core 2 for ASP.NET Core MVC 1st


Edition Adam Freeman

https://ebookmeta.com/product/pro-entity-framework-core-2-for-
asp-net-core-mvc-1st-edition-adam-freeman/

Pro ASP.NET Core 7, Tenth Edition (MEAP V03) Adam


Freeman

https://ebookmeta.com/product/pro-asp-net-core-7-tenth-edition-
meap-v03-adam-freeman/

Pro ASP.NET Core 7, MEAP V03 10th Edition Adam Freeman

https://ebookmeta.com/product/pro-asp-net-core-7-meap-v03-10th-
edition-adam-freeman/

Iranian Women in the Memoir Comparing Reading Lolita in


Tehran and Persepolis 1 and 2 1st Edition Emira Derbel

https://ebookmeta.com/product/iranian-women-in-the-memoir-
comparing-reading-lolita-in-tehran-and-persepolis-1-and-2-1st-
edition-emira-derbel/
Given 1st Edition Amy Pennza

https://ebookmeta.com/product/given-1st-edition-amy-pennza/

Mountain Daddy s Milk Honey Spice in the Mountains Book


1 1st Edition Elena Dawne

https://ebookmeta.com/product/mountain-daddy-s-milk-honey-spice-
in-the-mountains-book-1-1st-edition-elena-dawne/

Property Investing Essentials For Dummies Australian


Edition Nicola Mcdougall

https://ebookmeta.com/product/property-investing-essentials-for-
dummies-australian-edition-nicola-mcdougall/

The Artist 1st Edition Sheri Lewis Wohl

https://ebookmeta.com/product/the-artist-1st-edition-sheri-lewis-
wohl/

Digital Imaging of Artefacts Developments in Methods


and Aims 1st Edition Kate Kelley

https://ebookmeta.com/product/digital-imaging-of-artefacts-
developments-in-methods-and-aims-1st-edition-kate-kelley/
Pietro Monte s Collectanea The Arms Armour and Fighting
Techniques of a Fifteenth Century Soldier 6 Armour and
Weapons Jeffrey L Forgeng

https://ebookmeta.com/product/pietro-monte-s-collectanea-the-
arms-armour-and-fighting-techniques-of-a-fifteenth-century-
soldier-6-armour-and-weapons-jeffrey-l-forgeng/
Essential
Angular for
ASP.NET Core MVC

Adam Freeman

www.allitebooks.com
Essential Angular for
ASP.NET Core MVC

Adam Freeman

www.allitebooks.com
Essential Angular for ASP.NET Core MVC
Adam Freeman
London, UK
ISBN-13 (pbk): 978-1-4842-2915-6 ISBN-13 (electronic): 978-1-4842-2916-3
DOI 10.1007/978-1-4842-2916-3
Library of Congress Control Number: 2017949481
Copyright © 2017 by Adam Freeman
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are
not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material
contained herein.
Cover image by Freepik (www.freepik.com)
Managing Director: Welmoed Spahr
Editorial Director: Todd Green
Acquisitions Editor: Gwenan Spearing
Development Editor: Laura Berendson
Technical Reviewer: Fabio Claudio Ferracchiati
Coordinating Editor: Mark Powers
Copy Editor: Kim Wimpsett
Distributed to the book trade worldwide by Springer Science+Business Media New York,
233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
[email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC
and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc).
SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail [email protected], or visit www.apress.com/
rights-permissions.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book’s product page, located at www.apress.com/9781484229156. For more
detailed information, please visit www.apress.com/source-code.
Printed on acid-free paper

www.allitebooks.com
Dedicated to my lovely wife, Jacqui Griffyth.
(And also to Peanut.)

www.allitebooks.com
Contents at a Glance

About the Author�����������������������������������������������������������������������������������������������������xv


About the Technical Reviewer�������������������������������������������������������������������������������xvii


■Chapter 1: Understanding Angular and ASP.NET Core MVC����������������������������������� 1

■Chapter 2: Getting Ready��������������������������������������������������������������������������������������� 5

■Chapter 3: Creating the Project��������������������������������������������������������������������������� 21

■Chapter 4: Creating the Data Model�������������������������������������������������������������������� 43

■Chapter 5: Creating a Web Service���������������������������������������������������������������������� 69

■Chapter 6: Completing the Web Service������������������������������������������������������������ 103

■Chapter 7: Structuring an Angular Application������������������������������������������������� 135

■Chapter 8: Creating the Store���������������������������������������������������������������������������� 159

■Chapter 9: Completing the Angular Store���������������������������������������������������������� 187

■Chapter 10: Creating Administration Features�������������������������������������������������� 227

■Chapter 11: Securing the Application���������������������������������������������������������������� 251

■Chapter 12: Preparing for Deployment�������������������������������������������������������������� 279

Index��������������������������������������������������������������������������������������������������������������������� 295

www.allitebooks.com
Contents

About the Author�����������������������������������������������������������������������������������������������������xv


About the Technical Reviewer�������������������������������������������������������������������������������xvii


■Chapter 1: Understanding Angular and ASP.NET Core MVC����������������������������������� 1
Who Is This Book For?������������������������������������������������������������������������������������������������������ 1
What Does This Book Cover?�������������������������������������������������������������������������������������������� 1
What Doesn’t This Book Cover?��������������������������������������������������������������������������������������� 1
What Do You Need to Know?�������������������������������������������������������������������������������������������� 2
Are There Lots of Examples?�������������������������������������������������������������������������������������������� 2
Where Can You Get the Example Code?��������������������������������������������������������������������������� 4
Where Can You Get Corrections for This Book?���������������������������������������������������������������� 4
Contacting the Author������������������������������������������������������������������������������������������������������� 4
Summary�������������������������������������������������������������������������������������������������������������������������� 4

■Chapter 2: Getting Ready��������������������������������������������������������������������������������������� 5
Getting Ready on Windows����������������������������������������������������������������������������������������������� 5
Installing .NET Core�������������������������������������������������������������������������������������������������������������������������������� 6
Installing Node.js������������������������������������������������������������������������������������������������������������������������������������ 6
Installing Git�������������������������������������������������������������������������������������������������������������������������������������������� 8
Installing Docker������������������������������������������������������������������������������������������������������������������������������������� 8
Installing Visual Studio 2017���������������������������������������������������������������������������������������������������������������� 10
Installing Visual Studio Code���������������������������������������������������������������������������������������������������������������� 11

Getting Ready on Linux�������������������������������������������������������������������������������������������������� 12


Installing .NET Core������������������������������������������������������������������������������������������������������������������������������ 12
Installing Node.js���������������������������������������������������������������������������������������������������������������������������������� 13

vii

www.allitebooks.com
■ Contents

Installing Git������������������������������������������������������������������������������������������������������������������������������������������ 13
Installing Docker����������������������������������������������������������������������������������������������������������������������������������� 14
Installing Visual Studio Code���������������������������������������������������������������������������������������������������������������� 15

Getting Ready on macOS������������������������������������������������������������������������������������������������ 15


Installing .NET Core������������������������������������������������������������������������������������������������������������������������������ 16
Installing Node.js���������������������������������������������������������������������������������������������������������������������������������� 16
Installing Git������������������������������������������������������������������������������������������������������������������������������������������ 17
Installing Docker����������������������������������������������������������������������������������������������������������������������������������� 17
Installing Visual Studio Code���������������������������������������������������������������������������������������������������������������� 19

Summary������������������������������������������������������������������������������������������������������������������������ 19

■Chapter 3: Creating the Project��������������������������������������������������������������������������� 21
Preparing to Create a Project����������������������������������������������������������������������������������������� 21
Creating the Project�������������������������������������������������������������������������������������������������������� 22
Creating the Angular Part of the Project����������������������������������������������������������������������������������������������� 22
Creating the ASP.NET Core MVC Part of the Project������������������������������������������������������������������������������ 24
Configuring the Project������������������������������������������������������������������������������������������������������������������������� 25
Removing Files������������������������������������������������������������������������������������������������������������������������������������� 30
Updating the Controller, Layout, and View�������������������������������������������������������������������������������������������� 30

Running the Project�������������������������������������������������������������������������������������������������������� 32


Understanding the Combined Project and Tools������������������������������������������������������������� 34
Understanding the Structure of the Project������������������������������������������������������������������������������������������ 34
Understanding the Tool Integration������������������������������������������������������������������������������������������������������� 35
Detecting TypeScript Errors������������������������������������������������������������������������������������������������������������������ 38

Summary������������������������������������������������������������������������������������������������������������������������ 41

■Chapter 4: Creating the Data Model�������������������������������������������������������������������� 43
Preparing for This Chapter��������������������������������������������������������������������������������������������� 43
Starting the Data Model������������������������������������������������������������������������������������������������� 44
Preparing the Database Server������������������������������������������������������������������������������������������������������������ 44
Creating the ASP.NET Core MVC Data Model���������������������������������������������������������������������������������������� 46
Starting the Angular Data Model���������������������������������������������������������������������������������������������������������� 54

viii

www.allitebooks.com
■ Contents

Understanding the TypeScript Data Model Classes������������������������������������������������������������������������������ 56


Integrating the Angular Data Model������������������������������������������������������������������������������������������������������ 60
Displaying the Data������������������������������������������������������������������������������������������������������������������������������ 63

Reviewing the Application Structure������������������������������������������������������������������������������ 66


Reviewing the ASP.NET Core MVC Application Structure���������������������������������������������������������������������� 67
Reviewing the Angular Application Structure��������������������������������������������������������������������������������������� 67

Summary������������������������������������������������������������������������������������������������������������������������ 68

■Chapter 5: Creating a Web Service���������������������������������������������������������������������� 69
Preparing for This Chapter��������������������������������������������������������������������������������������������� 70
Introducing a Web Service��������������������������������������������������������������������������������������������� 71
Understanding RESTful Web Services�������������������������������������������������������������������������������������������������� 71
Creating the Web Service��������������������������������������������������������������������������������������������������������������������� 72
Using the Web Service in the Angular Application�������������������������������������������������������������������������������� 74
Loading Related Data��������������������������������������������������������������������������������������������������������������������������� 81

Implementing the GET Method for Multiple Objects������������������������������������������������������� 90


Implementing the Web Service Action Method������������������������������������������������������������������������������������� 90
Querying Multiple Objects in the Angular Application�������������������������������������������������������������������������� 92
Filtering the Data���������������������������������������������������������������������������������������������������������������������������������� 96

Understanding the Structure of the Web Service��������������������������������������������������������� 100


Summary���������������������������������������������������������������������������������������������������������������������� 101

■Chapter 6: Completing the Web Service������������������������������������������������������������ 103
Preparing for This Chapter������������������������������������������������������������������������������������������� 103
Implementing the POST Method����������������������������������������������������������������������������������� 104
Understanding the API Enhancements����������������������������������������������������������������������������������������������� 104
Creating the Data Binding Classes����������������������������������������������������������������������������������������������������� 105
Implementing the Web Service Action Methods��������������������������������������������������������������������������������� 107
Creating Data Objects in the Angular Application������������������������������������������������������������������������������� 110

Implementing the PUT Method������������������������������������������������������������������������������������� 115


Implementing the Web Service Action Methods��������������������������������������������������������������������������������� 115
Replacing Products in the Angular Application����������������������������������������������������������������������������������� 117

ix

www.allitebooks.com
■ Contents

Implementing the PATCH Method��������������������������������������������������������������������������������� 120


Understanding JSON Patch���������������������������������������������������������������������������������������������������������������� 121
Enhancing the Product Binding Target����������������������������������������������������������������������������������������������� 122
Implementing the Web Service Action Method����������������������������������������������������������������������������������� 123
Updating Objects in the Angular Application�������������������������������������������������������������������������������������� 124

Implementing the DELETE Method������������������������������������������������������������������������������� 127


Configuring the Database������������������������������������������������������������������������������������������������������������������� 128
Implementing the Web Service Action Method����������������������������������������������������������������������������������� 130
Deleting Objects in the Angular Application��������������������������������������������������������������������������������������� 131

Summary���������������������������������������������������������������������������������������������������������������������� 134

■Chapter 7: Structuring an Angular Application������������������������������������������������� 135
Preparing for This Chapter������������������������������������������������������������������������������������������� 136
Using the Data Model for Component Cooperation������������������������������������������������������ 137
Creating the Display Component�������������������������������������������������������������������������������������������������������� 137
Creating the Filter Component������������������������������������������������������������������������������������������������������������ 140
Applying the New Components���������������������������������������������������������������������������������������������������������� 141
Understanding the Application Structure�������������������������������������������������������������������������������������������� 143
Adding Another Component���������������������������������������������������������������������������������������������������������������� 143

Understanding Angular Routing����������������������������������������������������������������������������������� 147


Creating the Routing Configuration���������������������������������������������������������������������������������������������������� 147
Applying the Routing Configuration���������������������������������������������������������������������������������������������������� 149
Navigating Using Routes�������������������������������������������������������������������������������������������������������������������� 150
Improving Navigation�������������������������������������������������������������������������������������������������������������������������� 153
Understanding the Application Structure�������������������������������������������������������������������������������������������� 158

Summary���������������������������������������������������������������������������������������������������������������������� 158

■Chapter 8: Creating the Store���������������������������������������������������������������������������� 159
Preparing for This Chapter������������������������������������������������������������������������������������������� 160
Starting the Product Selection Feature������������������������������������������������������������������������ 161
Blocking Out the Feature Components����������������������������������������������������������������������������������������������� 161
Configuring the Angular URL Routes�������������������������������������������������������������������������������������������������� 167
Removing the Layout Header������������������������������������������������������������������������������������������������������������� 167
x

www.allitebooks.com
■ Contents

Displaying the Product List������������������������������������������������������������������������������������������ 168


Understanding the Product List Template Features���������������������������������������������������������������������������� 169

Creating the Category Filter����������������������������������������������������������������������������������������� 171


Enhancing the ASP.NET Core MVC Application������������������������������������������������������������������������������������ 172
Receiving Category Data in the Angular Data Repository������������������������������������������������������������������� 173
Updating the Filter Component and Template������������������������������������������������������������������������������������ 174

Creating the Pagination Controls���������������������������������������������������������������������������������� 176


Creating and Registering a Pagination Service���������������������������������������������������������������������������������� 176
Updating the Pagination Button Component��������������������������������������������������������������������������������������� 178
Paging the Product Data��������������������������������������������������������������������������������������������������������������������� 180

Displaying Ratings�������������������������������������������������������������������������������������������������������� 181


Adding the Font Awesome Package��������������������������������������������������������������������������������������������������� 181
Updating the Rating Component and Template���������������������������������������������������������������������������������� 182
Applying the Rating Component��������������������������������������������������������������������������������������������������������� 184

Summary���������������������������������������������������������������������������������������������������������������������� 186

■Chapter 9: Completing the Angular Store���������������������������������������������������������� 187
Preparing for This Chapter������������������������������������������������������������������������������������������� 187
Creating the Shopping Cart������������������������������������������������������������������������������������������ 188
Extending the Angular Data Model����������������������������������������������������������������������������������������������������� 188
Registering the Cart as a Service������������������������������������������������������������������������������������������������������� 190
Wiring Up the Buttons������������������������������������������������������������������������������������������������������������������������� 191
Creating the Cart Summary Component��������������������������������������������������������������������������������������������� 191
Displaying the Cart Detail������������������������������������������������������������������������������������������������������������������� 193

Storing Carts���������������������������������������������������������������������������������������������������������������� 197


Extending the ASP.NET Core MVC Data Model������������������������������������������������������������������������������������ 198
Creating the Cart Storage Web Service���������������������������������������������������������������������������������������������� 199
Storing and Retrieving Cart Data�������������������������������������������������������������������������������������������������������� 203

Creating the Checkout Process������������������������������������������������������������������������������������ 206


Extending the ASP.NET Core MVC Data Model������������������������������������������������������������������������������������ 206
Creating the ASP.NET Core MVC Web Service������������������������������������������������������������������������������������� 208
Creating the Angular Checkout Process��������������������������������������������������������������������������������������������� 210
xi

www.allitebooks.com
■ Contents

Creating the Checkout Components��������������������������������������������������������������������������������������������������� 213


Registering the Components and Creating the Routes����������������������������������������������������������������������� 220
Storing Checkout Details as Session Data������������������������������������������������������������������������������������������ 223

Summary���������������������������������������������������������������������������������������������������������������������� 226

■Chapter 10: Creating Administration Features�������������������������������������������������� 227
Preparing for This Chapter������������������������������������������������������������������������������������������� 227
Adding Administration Features����������������������������������������������������������������������������������� 229
Creating the Administration Components������������������������������������������������������������������������������������������� 230

Administering Products������������������������������������������������������������������������������������������������ 235


Creating the Editor Component���������������������������������������������������������������������������������������������������������� 236
Creating the Product Table����������������������������������������������������������������������������������������������������������������� 238

Administering Orders��������������������������������������������������������������������������������������������������� 242


Dealing with Request Errors����������������������������������������������������������������������������������������� 244
Creating the Error Handling and Distribution Service������������������������������������������������������������������������� 244
Displaying Errors�������������������������������������������������������������������������������������������������������������������������������� 246
Reporting Validation Errors����������������������������������������������������������������������������������������������������������������� 247

Summary���������������������������������������������������������������������������������������������������������������������� 249

■Chapter 11: Securing the Application���������������������������������������������������������������� 251
Preparing for This Chapter������������������������������������������������������������������������������������������� 251
Restricting Access to Action Methods�������������������������������������������������������������������������� 253
Restricting Access to Suppliers���������������������������������������������������������������������������������������������������������� 253
Restricting Access to Orders�������������������������������������������������������������������������������������������������������������� 253
Restricting Access to Products����������������������������������������������������������������������������������������������������������� 254
Testing the Restrictions���������������������������������������������������������������������������������������������������������������������� 257

Installing and Configuring ASP.NET Core Identity��������������������������������������������������������� 258


Installing the ASP.NET Core Identity NuGet Package�������������������������������������������������������������������������� 258
Creating the Identity Context Class and Seed Data���������������������������������������������������������������������������� 258
Adding Identity to the Application Configuration�������������������������������������������������������������������������������� 260
Creating the Database Migration�������������������������������������������������������������������������������������������������������� 263

xii
■ Contents

Creating the Authentication Controller and View���������������������������������������������������������� 263


Understanding the Conventional Authentication Flow������������������������������������������������������������������������ 265
Authenticating Directly in Angular������������������������������������������������������������������������������������������������������ 267
Testing the Client Authentication Process������������������������������������������������������������������������������������������ 278

Summary���������������������������������������������������������������������������������������������������������������������� 278

■Chapter 12: Preparing for Deployment�������������������������������������������������������������� 279
Preparing for This Chapter������������������������������������������������������������������������������������������� 279
Preventing Cross-Site Request Forgery Attacks���������������������������������������������������������� 280
Enabling Anti-CSRF Tokens����������������������������������������������������������������������������������������������������������������� 281
Sending and Receiving Anti-CSRF Tokens������������������������������������������������������������������������������������������ 283

Creating the Database Migration Command���������������������������������������������������������������� 286


Disabling Logging Messages���������������������������������������������������������������������������������������� 289
Disabling Automatic Angular Builds and Hot Modules������������������������������������������������� 290
Preparing the Angular Startup Sequence������������������������������������������������������������������������������������������� 291

Performing the Production Dry Run����������������������������������������������������������������������������� 292


Preparing the Database���������������������������������������������������������������������������������������������������������������������� 292
Building the Angular Application��������������������������������������������������������������������������������������������������������� 292
Starting the ASP.NET Core MVC Application���������������������������������������������������������������������������������������� 293

Summary���������������������������������������������������������������������������������������������������������������������� 294

Index��������������������������������������������������������������������������������������������������������������������� 295

xiii
About the Author

Adam Freeman is an experienced IT professional who has held senior


positions in a range of companies, most recently serving as chief
technology officer and chief operating officer of a global bank. Now retired,
he spends his time writing and long-distance running.

xv
About the Technical Reviewer

Fabio Claudio Ferracchiati is a senior consultant and a senior analyst/developer using Microsoft
technologies. He works for BluArancio (www.bluarancio.com). He is a Microsoft Certified Solution
Developer for .NET, a Microsoft Certified Application Developer for .NET, a Microsoft Certified Professional,
and a prolific author and technical reviewer. Over the past ten years, he’s written articles for Italian and
international magazines and coauthored more than ten books on a variety of computer topics.

xvii
CHAPTER 1

Understanding Angular
and ASP.NET Core MVC

This book is about using Angular and ASP.NET Core MVC together to build rich applications. Individually,
each of these frameworks is powerful and feature-rich, but using them together combines the dynamic
flexibility of Angular with the solid infrastructure of ASP.NET Core MVC.

Who Is This Book For?


This book is for ASP.NET Core MVC developers who want to add Angular to their projects but don’t know
where to start. Angular is a complex framework that can be overwhelming to learn, and this book provides
a solid foundation by using ASP.NET Core MVC to support an Angular application. By the end of this book,
you will understand how ASP.NET Core MVC and Angular can work together and will have gained a basic
understanding of how Angular development works.

What Does This Book Cover?


This book explains how to use Angular in an ASP.NET Core MVC project. I demonstrate how to create a
Visual Studio or Visual Studio Code project that contains Angular and ASP.NET Core MVC and show you
how to get them working together. I show you how to use Entity Framework Core to store the application
data and ASP.NET Core Identity to authenticate and authorize users. Each ASP.NET Core package adds its
complexities, and I show you how these can be managed to deliver functionality to Angular.
This book also introduces Angular development, focusing on just those features that are required by
most applications. I explain how Angular applications work, how to structure an Angular application, and
how individual building blocks can collaborate to create complex features.
The examples are based around SportsStore, which will be familiar if you have read any of my other
books. SportsStore is a fictional online store that contains the features that most projects need. The
SportsStore examples in this book have been adapted so that I can highlight problems between Angular
and ASP.NET Core MVC and explain how to solve them.

What Doesn’t This Book Cover?


This book is not a deep-dive into Angular or ASP.NET Core MVC. I assume you are already familiar with C#
and ASP.NET Core MVC development, and I describe only the essential Angular features.

© Adam Freeman 2017 1


A. Freeman, Essential Angular for ASP.NET Core MVC, DOI 10.1007/978-1-4842-2916-3_1
Chapter 1 ■ Understanding Angular and ASP.NET Core MVC

I have written other books that provide the deep-dive for each framework. If you are unfamiliar with
ASP.NET Core MVC development, then you should read Pro ASP.NET Core MVC before this book. Once
you have mastered the basics of Angular development, then Pro Angular provides a comprehensive tour of
Angular features.

What Do You Need to Know?


Before reading this book, you should have a working knowledge of ASP.NET Core MVC development and
have a good understanding of JavaScript, HTML, and CSS.

Are There Lots of Examples?


There are loads of examples. The best way to learn is by example, and I have packed as many of them as
I can into this book. To maximize the number of examples in this book, I have adopted a simple convention
to avoid listing the same code over and over again.
To help you navigate the project, the caption for each listing includes the name of the file and the folder
in which it can be found, like in Listing 1-1.

Listing 1-1. The Contents of the CheckoutState.cs File in the Models/BindingTargets Folder
namespace SportsStore.Models.BindingTargets {

    public class CheckoutState  {

        public string name { get; set; }


        public string address { get; set; }
        public string cardNumber { get; set; }
        public string cardExpiry { get; set; }
        public string cardSecurityCode { get; set; }
    }
}

This is a listing from Chapter 9, and the caption tells you that it refers to a file called CheckoutState.cs,
which can be found in the Models/BindingTargets folder. A project that combines Angular and ASP.NET
Core MVC can have a lot of files, and it is important to change the right one. (Don’t worry about the code in
this listing or the folder structure for the moment.)
When I make changes to a file, I show the altered statements in bold, like in Listing 1-2.

Listing 1-2. Adding Methods in the SessionValuesController.cs File in the Controllers Folder
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using SportsStore.Models;
using SportsStore.Models.BindingTargets;

namespace SportsStore.Controllers {

    [Route("/api/session")]
    public class SessionValuesController : Controller {

2
Chapter 1 ■ Understanding Angular and ASP.NET Core MVC

        [HttpGet("cart")]
        public IActionResult GetCart() {
            return Ok(HttpContext.Session.GetString("cart"));
        }

        [HttpPost("cart")]
        public void StoreCart([FromBody] ProductSelection[] products) {
            var jsonData = JsonConvert.SerializeObject(products);
            HttpContext.Session.SetString("cart", jsonData);
        }

        [HttpGet("checkout")]
        public IActionResult GetCheckout() {
            return Ok(HttpContext.Session.GetString("checkout"));
        }

        [HttpPost("checkout")]
        public void StoreCheckout([FromBody] CheckoutState data) {
            HttpContext.Session.SetString("checkout",
                JsonConvert.SerializeObject(data));
        }
    }
}

This is another listing from Chapter 9, and the bold statements indicate the changes that you should
make if you are following the example.
I use two different conventions to avoid repeating code in long files. For long class files, I omit methods
and properties, like in Listing 1-3.

Listing 1-3. Restricting Access in the SupplierValuesController.cs File in the Controllers Folder
using Microsoft.AspNetCore.Mvc;
using SportsStore.Models;
using SportsStore.Models.BindingTargets;
using System.Collections.Generic;
using Microsoft.AspNetCore.Authorization;

namespace SportsStore.Controllers {

    [Route("api/suppliers")]
    [Authorize(Roles = "Administrator")]
    public class SupplierValuesController : Controller {
        private DataContext context;

        // ...methods omitted for brevity...


    }
}

This listing from Chapter 11 shows you that a new attribute must be applied to the
SupplierValuesController class but doesn’t list the constructor or other methods, which remain
unchanged.

3
Chapter 1 ■ Understanding Angular and ASP.NET Core MVC

This is the convention that I follow to highlight changes to a region within a file, such as when new
statements are required in a single method in a long file, like in Listing 1-4.

Listing 1-4. Configuring the JSON Serializer in the Startup.cs File in the SportsStore Folder
...
public void ConfigureServices(IServiceCollection services) {
    services.AddDbContext<DataContext>(options =>
        options.UseSqlServer(Configuration
            ["Data:Products:ConnectionString"]));

    services.AddMvc().AddJsonOptions(opts => {
        opts.SerializerSettings.ReferenceLoopHandling
            = ReferenceLoopHandling.Serialize;
        opts.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
    });
}
...

This is a listing from Chapter 5 that requires a new statement in the ConfigureServices method of the
Startup class, which is defined in the Startup.cs file in the SportsStore folder, while the rest of the file
remains unchanged.

Where Can You Get the Example Code?


You can download the example projects for all the chapters in this book from https://github.com/apress/
esntl-angular-for-asp.net-core-mvc. The download is available without charge and includes all the
supporting resources that are required to re-create the examples without having to type them in. You don’t
have to download the code, but it is the easiest way of experimenting with the examples and makes it easy
to copy and paste code into your own projects.

Where Can You Get Corrections for This Book?


You can find corrections for this book in the Errata file in the GitHub repository for this book
(https://github.com/apress/esntl-angular-for-asp.net-core-mvc).

Contacting the Author


If you have problems making the examples in this chapter work or if you find a problem in the book, then
you can e-mail me at [email protected], and I will try my best to help. Please check the errata for this
book at https://github.com/apress/esntl-angular-for-asp.net-core-mvc to see if it contains a solution
to your problem before contacting me.

Summary
In this chapter, I described the purpose and content of this book, explained how you can download the
project used for each chapter of the book, and described the conventions I use in the code listings.
In the next chapter, I show you how to set up your development environment in preparation for creating a
combined Angular and ASP.NET Core MVC project in Chapter 3.

4
CHAPTER 2

Getting Ready

In this chapter, I explain how to set up the tools and packages required for Angular and ASP.NET Core MVC
development. There are instructions for Windows, Linux, and macOS, which are the three operating systems
that can be used for .NET Core projects. For quick reference, Table 2-1 lists the packages and explains their
purpose. Follow the instructions for your preferred operating system to install the tools that are required for
the rest of this book.

Table 2-1. The Software Packages Used in This Book

Name Description
Visual Studio Visual Studio is the Windows-only IDE that provides the full-featured development
experience for .NET.
Visual Studio Code Visual Studio Code is a lightweight IDE that can be used on Windows, macOS,
and Linux. It doesn’t provide the full range of features of the Windows-only Visual
Studio product but is well-suited to Angular and ASP.NET Core MVC development.
.NET SDK The .NET Core Software Development Kit includes the .NET runtime for
executing .NET applications and the development tools required to build and test
applications.
Node.js Node.js is used for many client-side development tools, delivered through its
package manager, NPM. It is used to prepare the Angular code for the browser.
Git Git is a revision control system. It is used by some of the NPM packages commonly
used for client-side development.
Docker The Docker package includes the tools required to run applications in containers.
The databases in this book are run inside Docker containers, which makes them
easy to install and manage.

Getting Ready on Windows


The following sections describe the setup required for Windows. All the tools used are available for free,
although some are offered in commercial versions with additional features (but these are not needed for the
examples in this book). If you are using Windows, you can use Visual Studio, which is the traditional IDE for
.NET projects, or Visual Studio Code, which offers a lighter-weight alternative.

© Adam Freeman 2017 5


A. Freeman, Essential Angular for ASP.NET Core MVC, DOI 10.1007/978-1-4842-2916-3_2
Chapter 2 ■ Getting Ready

Installing .NET Core


The .NET Core Software Development Kit (SDK) includes the runtime and development tools needed to
start the development project and perform database operations. To install the .NET Core SDK on Windows,
download the installer from https://download.microsoft.com/download/B/9/F/B9F1AF57-C14A-4670-
9973-CDF47209B5BF/dotnet-dev-win-x64.1.0.4.exe. This URL is for the 64-bit .NET Core SDK, which is
the version that I use throughout this book and which you should install to ensure that you get the expected
results from the examples. Rather than type in a complex URL, you can to go to https://www.microsoft.
com/net/download/core and select the 64-bit installer for the .NET Core SDK. (Microsoft also publishes a
runtime-only installer, but this does not contain the tools that are required for this book.)
Run the installer. Once the install process is complete, open a new PowerShell command prompt and
run the command shown in Listing 2-1 to check that .NET Core is working.

Listing 2-1. Testing .NET Core

dotnet --version

The output from this command will display the latest version of the .NET Core runtime that is installed.
If you have installed only the version specified, this will be 1.0.4.

Installing Node.js
Node.js is a runtime for server-side JavaScript applications and has become a popular platform for
development tools. In this book, Node.js is used by the Angular build tools to compile and prepare the code
that ASP.NET Core MVC will send to the browser.
It is important that you download the same version of Node.js that I use throughout this book. Although
Node.js is relatively stable, there are still breaking API changes from time to time, and they may stop the
examples from working. To install Node.js, download and run the installer from https://nodejs.org/dist/
v6.10.3/node-v6.10.3-x64.msi. This is the installer for version 6.10.3. You may prefer more recent releases
for your projects, but you should stick with the 6.10.3 release for the rest of this book. Run the installer and
ensure that the npm package manager and Add to PATH options are selected, as shown in Figure 2-1.

6
Chapter 2 ■ Getting Ready

Figure 2-1. Installing Node.js on Windows

The NPM package manager is used to download and install Node packages. Adding Node.js to the PATH
ensures that you can use the Node.js runtime at the command prompt just by typing node. Once you have
completed the installation, open a new command prompt and run the command shown in Listing 2-2.

Listing 2-2. Checking That Node.js Is Installed Correctly

node -v

You should see the following version number displayed: v6.9.2. If the installation has been successful,
then proceed to the “Installing NPM Packages” section.

Installing Bower
Once you have installed Node, run the command shown in Listing 2-3 to install the Bower package, which
is used to manage client-side packages.

Listing 2-3. Installing the Bower Package

npm install -g [email protected]

7
Chapter 2 ■ Getting Ready

Installing Git
The Git revision control tool is required to download the client-side packages used by the Bower package
installed in the previous section. Download and run the installer from https://git-scm.com/downloads.
When the installation is complete, open a new command prompt and run the command in Listing 2-4 to
check that Git is installed and working properly.

Listing 2-4. Checking the Git Install

git --version

This command prints out the version of the Git package that has been installed. At the time of writing,
the latest version of Git for Windows is 2.13.0.

Installing Docker
Docker is available in Community and Enterprise editions, the difference being the support and
certifications offered for the Enterprise edition. Both editions provide the same set of core features, and I use
the free Docker Community edition throughout this book.
Go to https://store.docker.com/editions/community/docker-ce-desktop-windows, click the
Get Docker CE for Windows (stable) link, and run the installer that is downloaded. Docker will start
automatically when the installation is complete. You may be prompted to enable Hyper-V, as shown in
Figure 2-2. Click the Ok button.

Figure 2-2. Enabling Hyper-V

Once the installation has completed, right-click the Docker icon in the taskbar and select Settings from
the pop-up menu. Navigate to the Advanced section and increase the memory allocated to Docker so that
it is at least 3500MB, which is the minimum required to run SQL Server, as shown in Figure 2-3. Click the
Apply button to save the configuration change and restart Docker with the new configuration.

8
Chapter 2 ■ Getting Ready

Figure 2-3. Assigning memory to Docker

Once Docker has restarted, open a new PowerShell command prompt and run the command shown in
Listing 2-5 to check that the installation was successful.

Listing 2-5. Checking That Docker Is Working

docker run --rm hello-world

Docker will download the files it needs to run a simple Hello World application. Docker will write out
messages like these, indicating that everything is working as expected (the command produces more output
than is shown here, but this is the important part):

...
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world

c04b14da8d14: Pull complete


Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
Status: Downloaded newer image for hello-world:latest

Hello from Docker!


This message shows that your installation appears to be working correctly.
...

9
Chapter 2 ■ Getting Ready

Installing Visual Studio 2017


Visual Studio is the traditional development environment for ASP.NET Core and Entity Framework Core
projects. It offers a full-featured development experience, but it can be resource hungry. Consider using
Visual Studio Code if you want a lighter-weight development experience, which I describe in the next
section.
Download the installer from https://www.visualstudio.com/vs. There are different editions of
Visual Studio 2017 available, but the free Community edition is sufficient for the examples in this book. Run
the installer and ensure that the .NET Core Cross-Platform Development workload is selected, as shown in
Figure 2-4.

Figure 2-4. Selecting the Visual Studio packages

Click the Install button to begin the process of downloading and installing the Visual Studio features.

Adding the Visual Studio Extensions


Two Visual Studio extensions are essential for working on ASP.NET Core MVC projects. The first is called
Razor Language Service, and it provides IntelliSense support for tag helpers when editing Razor views. The
second is called Project File Tools, and it provides automatic completion for editing .csproj files, which
simplifies the process of adding NuGet packages to projects.
Select Extensions and Updates from the Visual Studio Tools menu, select the Online section, and use
the search box to locate the extensions. Click the Download button, as shown in Figure 2-5, to download the
extension files.

10
Chapter 2 ■ Getting Ready

Figure 2-5. Downloading Visual Studio extensions

Click the Close button to dismiss the list of extensions and then close Visual Studio, which will trigger
the installation process for the extensions you downloaded. You will be prompted to accept the changes that
will be made and the license terms, as shown in Figure 2-6. Click the Modify button to install the extensions.
Once the process has completed, you can start Visual Studio and begin development.

Figure 2-6. Installing Visual Studio extensions

Installing Visual Studio Code


Visual Studio Code is a lightweight editor that doesn’t have all the features of the full Visual Studio product
but works across platforms and is perfectly capable of handling ASP.NET Core MVC and Entity Framework
Core projects.

11
Chapter 2 ■ Getting Ready

I find myself increasingly using Visual Studio Code, in part because it means I can use the same IDE on
different platforms and in part because it is more responsive and less resource hungry than Visual Studio 2017.
To install Visual Studio code, visit http://code.visualstudio.com and click the download link for
Windows. Run the installer and then start Visual Studio Code.
Once the installation is complete, start Visual Studio Code, click the Extensions button in the sidebar,
and locate and install the C# package, which provides support for working with C# code files.

Getting Ready on Linux


The following sections describe the setup required for Linux. Microsoft has taken Linux support for .NET
Core seriously because of its popularity as a deployment platform, which makes it a good platform for
development, too. .NET Core supports a range of Linux distributions, and I have used Ubuntu 16.04 for this
book, which is the current Long-Term Support (LTS) release at the time of writing.

Installing .NET Core


The .NET Core Software Development Kit (SDK) includes the runtime and development tools needed to
start the development project and perform database operations. The easiest way to install .NET Core on
Linux is to visit https://www.microsoft.com/net/core, select your distribution from the list, and copy and
paste the commands into a command prompt to ensure you don’t mistype any configuration arguments.
To install .NET Core SDK on Ubuntu 16.04, open a command prompt and enter the commands in
Listing 2-6 to configure package management so that Microsoft packages can be installed.

Listing 2-6. Preparing Package Management for .NET Core

sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/


xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893
sudo apt-get update

Run the command shown in Listing 2-7 to download and install the .NET Core SDK package. It is
important that you use the version number shown in the listing so that you get the expected results from the
examples in this book.

Listing 2-7. Installing the .NET Core Package

sudo apt-get install dotnet-dev-1.0.4

Once the package has been downloaded and installed, run the command shown in Listing 2-8 to check
that .NET Core is installed and working.

Listing 2-8. Testing the .NET Core Package

dotnet --version

The output from this command will display the latest version of the .NET Core runtime that is installed.
If you have installed only the version specified, this will be 1.0.4.

12
Chapter 2 ■ Getting Ready

Installing Node.js
N The easiest way to install Node.js is through a package manager, using the procedures described at
https://nodejs.org/en/download/package-manager. For Ubuntu, I ran the commands shown in
Listing 2-9 to download and install Node.js.

Listing 2-9. Installing Node.js on Ubuntu

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -


sudo apt-get install nodejs

Once you have installed Node.js, run the command shown in Listing 2-10 to check that the installation
was successful and that you have the right version.

Listing 2-10. Checking That Node.js Is Installed Correctly

node -v

You should see that version 6.x.x is installed. Version 6.10.3 is the latest at the time of writing, but there
may be updates pushed into the package manager feed for version 6.x by the time you read this.

Installing Bower
Once you have installed Node, run the command shown in Listing 2-11 to install the Bower package, which
is used to manage client-side packages.

Listing 2-11. Installing the Bower Package

sudo npm install -g [email protected]

Installing Git
Git is already installed on most Linux distributions. If you want to install the latest version, then consult the
installation instructions for your distribution at https://git-scm.com/download/linux. For Ubuntu, I used
the command in Listing 2-12.

Listing 2-12. Installing Git

sudo apt-get install git

Once you have completed the installation, open a new command prompt and run the command in
Listing 2-13 to check that Git is installed and available.

Listing 2-13. Checking the Git Install

git --version

13
Chapter 2 ■ Getting Ready

This command prints out the version of the Git package that was installed. At the time of writing, the
latest version of Git for Linux is 2.7.4.

Installing Docker
To install Docker on Linux, visit https://www.docker.com/community-edition, select the distribution that
you are using from the list, and follow the installation instructions, copying and pasting the commands to
avoid typos.
For Ubuntu 16.04, open a new command prompt and enter the commands in Listing 2-14 to configure
the package manager and install the prerequisite packages that Docker relies on.

Listing 2-14. Preparing the Package Manger and Installing Prerequisite Packages

sudo apt-get -y install apt-transport-https ca-certificates curl


curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
       "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
       $(lsb_release -cs) stable"
sudo apt-get update

To install Docker, run the command shown in Listing 2-15.

Listing 2-15. Installing Docker

sudo apt-get -y install docker-ce

Once Docker is installed, run the commands shown in Listing 2-16 so that you can use Docker without
sudo.

Listing 2-16. Configuring Docker So That Root Access Is Not Required

sudo groupadd docker


sudo usermod -aG docker $USER

Log out of your current session and log back in again for the commands in Listing 2-16 to take effect.
Once you have logged back in, run the command shown in Listing 2-17 to check that the installation has
been successful.

Listing 2-17. Checking That Docker Is Working

docker run --rm hello-world

14
Chapter 2 ■ Getting Ready

Docker will download the files it needs to run a simple Hello World application. Docker will write out
messages like these, indicating that everything is working as expected (the command produces more output
than is shown here, but this is the important part):

...
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world

c04b14da8d14: Pull complete


Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
Status: Downloaded newer image for hello-world:latest

Hello from Docker!


This message shows that your installation appears to be working correctly.
...

Once you have confirmed that Docker is installed and working properly, then run the command shown
in Listing 2-18 to install Docker Compose, which is required for the examples in this book.

Listing 2-18. Installing Docker Compose

sudo curl -L https://github.com/docker/compose/releases/download/1.13.0/docker-compose-


`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Once the installation is complete, run the command shown in Listing 2-19 to check that Docker
Compose works as expected.

Listing 2-19. Checking Docker Compose

docker-compose --version

If the installation has been successful, you will see this response: docker-compose version 1.13.0,
build 1719ceb.

Installing Visual Studio Code


To install Visual Studio code, visit http://code.visualstudio.com and click the download link for your
platform. Run the installer and then start Visual Studio Code, which will present a standard integrated
development environment.
Once the installation is complete, start Visual Studio Code, click the Extensions button in the sidebar,
and locate and install the C# package, which provides support for working with C# code files.

Getting Ready on macOS


The following sections describe the setup required for macOS, which provides a good platform .NET
development through Visual Studio Code. Although my main development machine runs Windows, my
laptop runs macOS, and I use it for development when traveling.

15
Chapter 2 ■ Getting Ready

Installing .NET Core


Before installing .NET Core, open a new command prompt and run the command in Listing 2-20 to install
the HomeBrew package manager.

Listing 2-20. Installing the Package Manager

/usr/bin/ruby -e \
  "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Once installation is complete, run the commands shown in Listing 2-21 to install the OpenSSL library,
which is a prerequisite for some .NET Core features.

Listing 2-21. Installing the OpenSSL Package

brew install openssl


mkdir -p /usr/local/lib
ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/

To install .NET Core on macOS, download the SDK installer from https://go.microsoft.com/
fwlink/?linkid=848823. This URL is for the .NET Core SDK version I use throughout this book and that you
should install to ensure you get the expected results from the examples.
Run the installer. Once the process is complete, open a Terminal window and run the command shown
in Listing 2-22 at the prompt to check that .NET Core is working.

Listing 2-22. Testing .NET Core

dotnet --version

The output from this command will display the latest version of the .NET Core runtime that is installed.
If you have installed only the version specified, this will be 1.0.4.

Installing Node.js
To install Node.js on macOS, download and run the installer available from https://nodejs.org/dist/
v6.10.3/node-v6.10.3.pkg. Once the installation is complete, open a new Terminal window and run the
command shown in Listing 2-23 at the command prompt once the installer has completed.

Listing 2-23. Checking That Node.js Is Installed Correctly

node -v

You should will see the following version number displayed: v6.10.3.

16

www.allitebooks.com
Chapter 2 ■ Getting Ready

Installing Bower
Once you have installed Node, run the command shown in Listing 2-24 to install the Bower package, which
is used to manage client-side packages.

Listing 2-24. Installing the Bower Package

sudo npm install -g [email protected]

Installing Git
The Git revision control tool is required to download the client-side packages used by the Bower package
installed in the previous section. Download and run the installer from https://git-scm.com/downloads.
When the installation is complete, open a new command prompt and run the command in Listing 2-25 to
check that Git is installed and working properly.

Listing 2-25. Checking the Git Install

git --version

This command prints out the version of the Git package that has been installed. At the time of writing,
the latest version of Git for macOS is 2.13.0.

Installing Docker
Go to https://store.docker.com/editions/community/docker-ce-desktop-mac, click the Get Docker for
CE Mac (stable) link, and run the installer that is downloaded. Drag the whale to the Applications folder, as
shown in Figure 2-7.

Figure 2-7. Installing Docker

17
Chapter 2 ■ Getting Ready

Open Launchpad and click the Docker icon to perform the setup process. Once Docker has started,
click the Docker menu bar icon and select Preferences from the pop-up menu.
Navigate to the Advanced section and increase the memory allocated to Docker so that it is at least
3500MB, which is the minimum required to run SQL Server, as shown in Figure 2-8. Click the Apply button
to save the configuration change and restart Docker with the new configuration.

Figure 2-8. Assigning memory to Docker

Click Apply & Restart to change the memory and restart the Docker process. When Docker is running
again, dismiss the Preferences window, open a new Terminal window, and run the command shown in
Listing 2-26 to check that the installation was successful.

Listing 2-26. Checking That Docker Is Working

docker run --rm hello-world

18
Chapter 2 ■ Getting Ready

Docker will download the files it needs to run a simple Hello World application. Docker will write out
messages like these, indicating that everything is working as expected (the command produces more output
than is shown here, but this is the important part):

...
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world

c04b14da8d14: Pull complete


Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
Status: Downloaded newer image for hello-world:latest

Hello from Docker!


This message shows that your installation appears to be working correctly.
...

Installing Visual Studio Code


Developing for .NET on macOS is done using Visual Studio Code. To install Visual Studio Code, visit
http://code.visualstudio.com, click the download link, run the installer, and then start Visual Studio Code.
Once the installation is complete, start Visual Studio Code, click the Extensions button in the sidebar,
and locate and install the C# package, which provides support for working with C# code files.

Summary
In this chapter, I explained how to install the tools and packages that are required to use Angular and ASP.
NET Core MVC, and in the next chapter, I show you how to create a project that combines them.

19
CHAPTER 3

Creating the Project

In this chapter, I show you how to create a project that contains ASP.NET Core MVC and Angular
applications, which means both parts of the project can be developed using Visual Studio or Visual Studio
Code. This project forms the foundation for the rest of this book, as I explain how to use Angular and
ASP.NET Core MVC to create a rich web application. Table 3-1 puts the combined project in context.

Table 3-1. Putting a Combined Project in Context

Question Answer
What is it? A combined project includes Angular and ASP.NET Core MVC in a single
folder structure.
Why is it useful? A combined project makes it easy to develop both parts of an application
using a single IDE, such as Visual Studio, as well as simplifying the process
of using an ASP.NET Core MVC web service to provide data to Angular.
How is it used? The Angular application is created first, followed by ASP.NET Core MVC.
Additional NuGet packages are used to allow both parts of the project to
work together at runtime.
Are there any pitfalls or A combined project makes managing the development process easier, but
limitations? you still need a good working knowledge of both Angular and ASP.NET Core
MVC to create an effective application.
Are there any alternatives? You can develop the Angular and ASP.NET Core MVC parts of the
application separately, although this tends to complicate the development
process.

■■Tip You can download the complete project for this chapter from https://github.com/apress/esntl-
angular-for-asp.net-core-mvc. This is also where you will find updates and corrections for this book.

Preparing to Create a Project


There are several different ways to create a project that combines Angular and ASP.NET Core MVC. The
approach that I use in this book relies on the @angular/cli package, used in conjunction with the .NET tools
for creating a new MVC project.

© Adam Freeman 2017 21


A. Freeman, Essential Angular for ASP.NET Core MVC, DOI 10.1007/978-1-4842-2916-3_3
Chapter 3 ■ Creating the Project

USING THE DOTNET NEW ANGULAR COMMAND

Microsoft provides a template that can be used to create a similar project structure (which you can
use by running dotnet new angular at the command line). The process I use in this chapter is more
manual, but it means you will understand how the different building blocks fit together and have a
better idea of where to look when you don’t get the results you expect. Once you are familiar with how
Angular and ASP.NET Core MVC can work together, using this template is perfectly reasonable, with the
caveat that you are unable to specify the versions of ASP.NET Core MVC and Angular that are used in
the project.

The @angular/cli package provides a command-line interface that simplifies the process of creating
and working with a new Angular project. During development, the Angular code is compiled, packaged, and
delivered to the browser using webpack, a popular tool for creating JavaScript bundles that contain only the
code required to run a project.
To create a project that combines Angular and ASP.NET Core MVC, I start with @angular/cli and access
he underlying webpack configuration, which can then be used to integrate the Angular tools and libraries
into the ASP.NET Core project.
To start this process, open a new command prompt and run the command in Listing 3-1 to install the
@angular/cli package. If you are using Linux or macOS, you may need to use sudo to run this command.

Listing 3-1. Installing the @angular/cli Package

npm install --global @angular/[email protected]

This command takes a while to run because the package has a lot of dependencies, all of which have to
be downloaded and installed.

Creating the Project


The process for creating a combined Angular and ASP.NET Core MVC project requires careful attention:
both development platforms have their tools and conventions, and getting them to work together requires
a specific set of steps to be performed in order. In the sections that follow, I walk through the process and
explain each step.

■■Tip You must follow each step exactly as shown, without missing a step or changing the order. If you get
stuck, then you can download a ready-made project from the source code repository, which is linked from the
Apress.com page for this book.

Creating the Angular Part of the Project


The first step is to create a new Angular project, which is done using the @angular/cli package installed
in Listing 3-1. Open a new command prompt, navigate to the folder where you keep your development
projects, and run the command shown in Listing 3-2.

22
Chapter 3 ■ Creating the Project

Listing 3-2. Creating an Angular Project

ng new SportsStore --skip-git --skip-commit --skip-tests --source-dir ClientApp

The ng command is provided by the @angular/cli package, and ng new creates a new Angular project.
The arguments that start with --skip tell @angular/cli not to perform some of the standard setup steps that
are usually included in projects, and the --source-dir argument specifies the name of the folder that will
contain the source code for the Angular application. The Angular code lives in a folder called ClientApp in
projects that combine Angular and ASP.NET Core MVC.
The command in Listing 3-2 creates a folder called SportsStore that contains the tools and
configuration files for an Angular project, along with some placeholder code so that the tools and project
structure can be tested. The ng new command downloads a large number of packages, which can take a long
time to complete.
The rest of the setup is performed inside the project folder, so run the command shown in Listing 3-3 to
change the working directory.

Listing 3-3. Changing the Working Directory

cd SportsStore

Getting the Angular tools to work with the .NET tools requires additional NPM packages. Run the
command shown in Listing 3-4 to install these packages.

Listing 3-4. Adding NPM Packages to the Project

npm install --save-dev [email protected] [email protected] [email protected]


[email protected]

Microsoft provides some of these NPM packages, and they are used to set up and run the Angular
development tools inside the ASP.NET Core runtime. These packages work directly with webpack, which is
usually hidden when working with projects created using @angular/cli. Run the command shown in
Listing 3-5 in the SportsStore folder to create a webpack configuration file that can be used to build and
run the project, a process known as ejecting the project from @angular/cli.

Listing 3-5. Ejecting the Project

ng eject

The ejection process updates the package.json file, which NPM uses to keep track of the packages used
by the project. In some cases, the ejection process will add additional NPM packages to the project.json file,
so run the command shown in Listing 3-6 to ensure that any new packages are downloaded and installed.

Listing 3-6. Updating the NPM Packages

npm install

23
Chapter 3 ■ Creating the Project

Creating the ASP.NET Core MVC Part of the Project


Once the Angular project has been set up, the next step is to create an MVC project in the same SportsStore
folder. Run the command shown in Listing 3-7 in the SportsStore folder to create a basic MVC project.

Listing 3-7. Creating the ASP.NET Core MVC Project

dotnet new mvc --language C# --auth None --framework netcoreapp1.1

Run the command shown in Listing 3-8 in the SportsStore folder to add a Microsoft package to the
project. This NuGet package is the .NET counterpart to the NPM packages installed earlier and is used to
integrate the Angular tools into Visual Studio.

Listing 3-8. Adding a NuGet Package to the Project

dotnet add package Microsoft.AspNetCore.SpaServices --version 1.1.0

The application will be stored using Microsoft SQL Server and accessed using Entity Framework Core.
Run the commands shown in Listing 3-9 in the SportsStore folder to add the NuGet packages required to
add these features to the application.

Listing 3-9. Adding the Data NuGet Packages to the Project

dotnet add package Microsoft.EntityFrameworkCore --version 1.1.1


dotnet add package Microsoft.EntityFrameworkCore.Design --version 1.1.1
dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 1.1.1

Not all the required packages can be added using the command-line tools. Open the project using
Visual Studio or Visual Studio Code. If you are using Visual Studio, then select File ➤ Open ➤ Project/Solution,
navigate to the SportsStore folder, and select the SportsStore.csproj file. To edit the NuGet packages,
right-click the SportsStore project item in the Solution Explorer, select Edit SportsStore.csproj from the pop-
up menu, and make the changes shown in Listing 3-10.
If you are using Visual Studio Code, open the SportsStore project, click SportsStore.csproj in the file
list to open the file for editing, and make the changes shown in Listing 3-10.

Listing 3-10. Adding NuGet Packages in the SportsStore.csproj File in the SportsStore Folder
<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="1.1.0" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design"
         Version="1.1.1" />

24
Chapter 3 ■ Creating the Project

    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer"
         Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink"
         Version="1.1.0" />

    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools"
         Version="1.0.0" />
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet"
         Version="1.0.0" />
  </ItemGroup>
</Project>

If you are using Visual Studio, the new packages will be downloaded when you save the SportsStore.
csproj file. If you are using Visual Studio Code, use a command prompt to run the command shown in
Listing 3-11 in the SportsStore folder.

Listing 3-11. Restoring Packages

dotnet restore

Configuring the Project


Now that the project foundation is in place, it is time to configure the different parts of the application to
work together.

Preparing the Project ( Visual Studio)


If you are using Visual Studio, select File ➤ Open Project/Solution, navigate to the SportsStore folder, and
select the SportsStore.csproj file. Select File ➤ Save All and save the SportsStore.sln file, which you can
use to open the project in the future.
Select Project ➤ SportsStore Properties, navigate to the Debug section of the options window, and
ensure that IIS Express is selected for the Launch field, as shown in Figure 3-1.

25
Chapter 3 ■ Creating the Project

Figure 3-1. Configuring the application

Ensure that the Launch URL button is selected and enter http://localhost:5000 in the App URL field,
as shown in Figure 3-1. Finally, click the Add button to create an environment variable called ASPNETCORE_
ENVIRONMENT, if it doesn’t already exist, with a value of Development. Save the changes and close the
properties window.

Creating and Editing the Configuration Files


Regardless of the IDE you are using, add a TypeScript file called boot.ts to the SportsStore/ClientApp
folder, with the code shown in Listing 3-12.

Listing 3-12. The Contents of the boot.ts File in the ClientApp Folder
import { enableProdMode } from "@angular/core";
import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";
import { AppModule } from "./app/app.module";

const bootApplication = () => {


    platformBrowserDynamic().bootstrapModule(AppModule);
};

26
Chapter 3 ■ Creating the Project

if (module["hot"]) {
    module["hot"].accept();
    module["hot"].dispose(() => {
        const oldRootElem = document.querySelector("app-root");
        const newRootElem = document.createElement("app-root");
        oldRootElem.parentNode.insertBefore(newRootElem, oldRootElem);
        platformBrowserDynamic().destroy();
    });
}

if (document.readyState === "complete") {


    bootApplication();
} else {
    document.addEventListener("DOMContentLoaded", bootApplication);
}

This file is responsible for loading the Angular application and responding to changes to the client-side
code. Next, edit the Startup.cs file to change the code in the Configure method, as shown in Listing 3-13.
The additions enable the integration between the ASP.NET Core and Angular development tools.

Listing 3-13. Enabling Middleware in the Startup.cs File in the SportsStore Folder
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.SpaServices.Webpack;

namespace SportsStore {
    public class Startup {
        public Startup(IHostingEnvironment env) {
            var builder = new ConfigurationBuilder()
              .SetBasePath(env.ContentRootPath)
              .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
              .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
              .AddEnvironmentVariables();
            Configuration = builder.Build();
        }

        public IConfigurationRoot Configuration { get; }

        public void ConfigureServices(IServiceCollection services) {


            services.AddMvc();
        }

        public void Configure(IApplicationBuilder app,


                IHostingEnvironment env, ILoggerFactory loggerFactory) {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

27
Chapter 3 ■ Creating the Project

            app.UseDeveloperExceptionPage();
            app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions {
                HotModuleReplacement = true
            });

            //if (env.IsDevelopment()) {
            //  app.UseDeveloperExceptionPage();
            //  app.UseBrowserLink();
            //} else {
            //  app.UseExceptionHandler("/Home/Error");
            //}

            app.UseStaticFiles();

            app.UseMvc(routes => {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }
}

Open the webpack.config.js file in the SportsStore folder, locate the module.exports statement
shown in Listing 3-14, and make the changes in bold. This file contains a lot of configuration statements,
but the ones you are looking for are close to the top of the file.

Listing 3-14. Setting the Public Path in the webpack.config.js File in the SportsStore Folder
...
module.exports = {
  "devtool": "source-map",
  "resolve": {
    "extensions": [".ts",".js"],
    "modules": ["./node_modules"]
  },
  "resolveLoader": {"modules": ["./node_modules"]},
  "entry": {
    "main": [
        "./ClientApp\\boot.ts"
    ],
    "polyfills": [
      "./ClientApp\\polyfills.ts"
    ],
    "styles": [
      "./ClientApp\\styles.css"
    ]
  },
  "output": {
    "path": path.join(process.cwd(), "wwwroot/dist"),

28
Chapter 3 ■ Creating the Project

    "filename": "[name].bundle.js",
    "chunkFilename": "[id].chunk.js",
    "publicPath": "/app/"
  },
"module": {
      "rules": [{
          "enforce": "pre", "test": /\.js$/, "loader": "source-map-loader",
...

Enabling Logging Messages


During development, it can be useful to see details of the build process for the Angular application and
details of the queries sent to the database by Entity Framework Core. To enable logging messages, add the
configuration statements shown in Listing 3-15 to the appsettings.json file.

Listing 3-15. Enabling Logging in the appsettings.json File in the SportsStore Folder
{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Microsoft.EntityFrameworkCore": "Information",
      "Microsoft.AspNetCore.NodeServices": "Information",
      "Default": "Warning"
    }
  }
}

Updating the Bootstrap Package


Throughout this book, I use the Bootstrap CSS package to style the HTML elements displayed by the
browser. To update the version used in the project, edit the bower.json file in the SportsStore folder
and make the change shown in Listing 3-16.

USING THE BOOTSTRAP PRERELEASE

Throughout this book, I use a prerelease version of the Bootstrap CSS framework. As I write this, the
Bootstrap team is in the process of developing Bootstrap version 4 and has made several early releases.
These releases are labeled as “alpha,” but the quality is high, and they are stable enough for use in the
examples in this book.
Given the choice of writing this book using the soon-to-be-obsolete Bootstrap 3 and a prerelease
version of Bootstrap 4, I decided to use the new version even though some of the class names that
are used to style HTML elements are likely to change before the final release. You must use the same
version of Bootstrap to get the expected results from the examples, just like the rest of the packages
used in this book.

29
Chapter 3 ■ Creating the Project

Listing 3-16. Updating Bootstrap in the bower.json File in the SportsStore Folder
{
  "name": "asp.net",
  "private": true,
  "dependencies": {
    "bootstrap": "4.0.0-alpha.6",
    "jquery": "2.2.0",
    "jquery-validation": "1.14.0",
    "jquery-validation-unobtrusive": "3.2.6"
  }
}

Save the change. If you are using Visual Studio Code, use a command prompt to run the command
shown in Listing 3-17 to download the Bootstrap package. (This is done automatically by Visual Studio.)

Listing 3-17. Updating the Client-Side Packages

bower install

Removing Files
Some files in the project can be removed. Table 3-2 describes the files that are not required in this book.
You don’t have to remove these files, but it will help simplify the project structure and, in the case of the
.editorconfig file, avoid confusion when your code editor doesn’t respect your normal preferences.

Table 3-2. Files That Can Be Removed

Name Description
.editorconfig This file contains project-specific editor configuration settings, and it is used
by Visual Studio to override the preferences specified by the Tools ➤ Options
menu, including setting the tab size to two spaces.
e2e This folder contains tests for Protractor, which does end-to-end testing for
Angular applications. See www.protractortest.org for details.
protractor.conf.js This file contains configuration settings for Protractor.
README.md This file contains welcome text containing an overview of the @angular/cli tools.

Updating the Controller, Layout, and View


The final step in setting up the project is to update the controller and the Razor layout and view to replace
the placeholder content and incorporate the Angular application. Edit the Home controller and replace the
contents with the code shown in Listing 3-18.

30
Chapter 3 ■ Creating the Project

Listing 3-18. Replacing Content in the HomeController.cs File in the Controllers Folder
using Microsoft.AspNetCore.Mvc;

namespace SportsStore.Controllers {
    public class HomeController : Controller {

        public IActionResult Index() {


            return View();
        }
    }
}

Edit the _Layout.cshtml file in the Views/Shared folder and replace the content with the elements
shown in Listing 3-19.

Listing 3-19. Replacing Content in the _Layout.cshtml File in the Views/Shared Folder
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>SportsStore @ViewData["Title"]</title>
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
</head>
<body>
    @RenderBody()
    @RenderSection("Scripts", required: false)
</body>
</html>

Edit the Index.cshtml file in the Views/Home folder and replace the contents with those shown in
Listing 3-20.

Listing 3-20. Replacing Content in the Index.cshtml File in the Views/Home Folder
@section scripts {
  <script src="~/dist/inline.bundle.js" asp-append-version="true"></script>
  <script src="~/dist/polyfills.bundle.js" asp-append-version="true"></script>
  <script src="~/dist/vendor.bundle.js" asp-append-version="true"></script>
  <script src="~/dist/main.bundle.js" asp-append-version="true"></script>
}

<div class="navbar bg-inverse">


  <a class="navbar-brand text-white">@(ViewBag.Message ?? "SPORTS STORE")</a>
</div>
<div class="p-1">
  <app-root></app-root>
</div>

31
Chapter 3 ■ Creating the Project

The script elements in this view include bundles of JavaScript files that contain the Angular framework
and the client-side application code. These bundles will be created automatically by webpack when the files
in the Angular part of the project change.
The app-root element will be replaced with dynamic content produced by the Angular application, as
you will see in the next section. The other elements are standard HTML that has been styled with Bootstrap.

Running the Project


If you are using Visual Studio, then start the application by selecting Start Without Debugging from the
Debug menu. A new browser window will open and request http://localhost:5000, which was the URL
you used to configure the project earlier in the chapter, showing the content in Figure 3-2.
If you are using Visual Studio Code, then use a command window to run the command shown in
Listing 3-21 in the SportsStore folder, which will build the project and start the ASP.NET Core HTTP server.

Listing 3-21. Starting the Project

dotnet run

Open a new browser window and navigate to http://localhost:5000. If you have followed all of the
configuration steps, you will see the content shown in Figure 3-2.

Figure 3-2. Testing the application

■■Tip It can take a moment for the application to deliver the content to the client for the first HTTP request.
Reload the browser page if you just see the SportsStore header but not the “app works!” message.

This may not seem like an impressive result, but the Angular development tools and ASP.NET Core are
now working together. Edit the app.component.ts file in the SportsStore/ClientApp/app folder and
make the change highlighted in Listing 3-22. (You will have to expand the app.component.html file to see
the app.component.ts file in the Solution Explorer if you are using Visual Studio, which nests related files
together.)

32
Discovering Diverse Content Through
Random Scribd Documents
for the safety of the citizen as well as that for their own protection, may declare by law
what is necessary and proper to enable them to carry into execution the powers vested
in them, and thereby hang up a rule for the inspection of all, which may direct the
conduct of the citizen, and at the same time test the judgments they shall themselves
pronounce in their own case.]

Privilege from arrest takes place by force of the election; and before a return be made a
member elected may be named of a committee, and is to every extent a member, except
that he cannot vote until he is sworn. Memor., 107, 108. D’Ewes, 642, col. 2; 643, col. 1.
Pet. Miscel. Parl., 119. Lex. Parl. c. 23. 2 Hats., 22, 62.

Every man must, at his peril, take notice who are members of either House returned of
record. Lex. Parl., 23; 4 Inst., 24.

On complaint of a breach of privilege, the party may either be summoned or sent for in
custody of the sergeant. Grey, 88, 95.

The privilege of a member is the privilege of the House. If the member waive it without
leave, it is a ground for punishing him, but cannot in effect waive the privilege of the
House. 3 Grey, 140, 222.

For any speech or debate in either House, they shall not be questioned in any other
place. Const. U. S., I, 6,; S. P. protest of the Commons to James I., 1621; 2 Rapin, No.
54, pp. 211, 212. But this is restrained to things done in the House in a parliamentary
course. 1 Rush., 663. For he is not to have privilege contra morem parliamentarum, to
exceed the bounds and limits of his place and duty. Com. p.

If an offense be committed by a member of the House, of which the House has


cognizance, it is an infringement of their right for any person or court to take notice of it,
till the House has punished the offender, or referred him to a due course. Lex. Parl., 63.

Privilege is in the power of the House, and is a restraint to proceedings of inferior courts,
but not of the House itself. 2 Nalson, 450; 2 Grey, 399. For whatever is spoken in the
House is subject to the censure of the House; and offenses of this kind have been
severely punished by calling the person to the bar to make submission, committing him
to the tower, expelling the House, etc. Scob., 72; L. Parl., c. 22.

It is a breach of order for the Speaker to refuse to put a question which is in order. 2
Hats., 175-6; 5 Grey, 133.

And even in cases of treason, felony, and breach of the peace, to which privilege does
not extend as to substance, yet in Parliament a member is privileged as to the mode of
proceeding. The case is first to be laid before the House, that it may judge of the fact
and of the grounds of the accusation, and how far forth the manner of the trial may
concern their privilege; otherwise it would be in the power of other branches of the
government, and even of every private man, under pretenses of treason, etc., to take
any man from his service in the House, and so as many, one after another, as would
make the House what he pleaseth. Dec. of the Com. on the King’s declaring Sir John
Hotham a traitor. 4 Rushw., 586. So, when a member stood indicted for felony, it was
adjudged that he ought to remain of the House till conviction; for it may be any man’s
case, who is guiltless, to be accused and indicted of felony, or the like crime. 23 El.,
1580; D’Ewes, 283, col. 1; Lex. Parl., 133.

When it is found necessary for the public service to put a member under arrest, or when,
on any public inquiry, matter comes out which may lead to affect the person of a
member, it is the practice immediately to acquaint the House, that they may know the
reasons for such a proceeding, and take such steps as they think proper. 2 Hats., 259. Of
which see many examples. Ib., 256, 257, 258. But the communication is subsequent to
the arrest. 1 Blackst., 167.

It is highly expedient, says Hatsel, for the due preservation of the privileges of the
separate branches of the Legislature, that neither should encroach on the other, or
interfere in any matter depending before them, so as to preclude, or even influence that
freedom of debate, which is essential to a free council. They are therefore not to take
notice of any bills or other matters depending, or of votes that have been given, or of
speeches which have been held, by the members of either of the other branches of the
Legislature, until the same have been communicated to them in the usual parliamentary
manner. 2 Hats., 252. 4 Inst., 15. Seld. Jud., 53. Thus the king’s taking notice of the bill
for suppressing soldiers, depending before the House; his proposing a provisional clause
for a bill before it was presented to him by the two Houses; his expressing displeasure
against some persons for matters moved in parliament during the debate and
preparation of a bill, were breaches of privilege; 2 Nalson, 347; and in 1783, December
17, it was declared a breach of fundamental privileges, etc., to report any opinion or
pretended opinion of the king on any bill or proceeding depending in either House of
Parliament, with a view to influence the votes of the members. 2 Hats., 251, 6.

SECTION IV.

ELECTIONS.

[The times, places, and manner of holding elections for senators and representatives
shall be prescribed in each State by the Legislature thereof; but the Congress may at any
time by law make or alter such regulations, except as to the places of choosing senators.
Const. I., 4.]

[Each House shall be the judge of the elections, returns, and qualifications of its own
members. Const. I., 5.]

SECTION V.

QUALIFICATIONS.
[The Senate of the United States shall be composed of two Senators from each State,
chosen by the Legislature thereof for six years; and each Senator shall have one vote.]

[Immediately after they shall be assembled in consequence of the first election, they
shall be divided, as equally as may be into three classes. The seats of the Senators of
the first class shall be vacated at the end of the second year; of the second class, at the
expiration of the fourth year; and of the third class, at the expiration of the sixth year; so
that one-third may be chosen every second year; and if vacancies happen, by
resignation or otherwise, during the recess of the Legislature of the State, any Executive
thereof may make temporary appointments, until the next meeting of the Legislature,
which shall then fill such vacancies.]

[No person shall be a Senator who shall not have attained to the age of thirty years, and
been nine years a citizen of the United States, and who shall not, when elected, be an
inhabitant of that State for which he shall be chosen. Const. I., 3.]

[The House of Representatives shall be composed of members chosen every second year
by the people of the several States; and the electors of each State shall have the
qualifications requisite for electors of the most numerous branch of the State
Legislature.]

[No person shall be a Representative who shall not have attained to the age of twenty-
five years, and been seven years a citizen of the United States, and who shall not, when
elected, be an inhabitant of that State in which he shall be chosen.]

[Representatives and direct taxes shall be apportioned among the several States which
may be included within this Union, according to their respective numbers; which shall be
determined by adding to the whole number of free persons, including those bound to
service for a term of years, and excluding Indians not taxed, three-fifths of all other
persons. The actual enumeration shall be made within three years after the first meeting
of the Congress of the United States, and within every subsequent term of ten years, in
such manner as they shall by law direct. The number of representatives shall not exceed
one for every thirty thousand, but each State shall have at least one representative.
Constitution of the United States, I., 2.]

The provisional apportionments of Representatives made in the Constitution in 1787, and


afterwards by Congress, were as follows:

STATES. 17874 17905 18006 18107 18208 18309 184010 185011 186012 187013
14 Maine 7 8 7 7 6 5 5
New
3 4 5 6 6 5 4 3 3 3
Hampshire
Massachusetts 8 14 17 20 13 12 10 11 10 11
Rhode Island 1 2 2 2 2 2 2 2 2 2
Connecticut 5 7 7 7 6 6 4 4 4 4
Vermont 2 4 6 5 5 4 3 3 3
New York 6 10 17 27 34 40 34 33 31 33
New Jersey 4 5 6 6 6 6 5 4 5 7
Pennsylvania 8 13 18 23 26 28 34 25 24 27
Delaware 1 1 1 2 1 1 1 1 1 1
Maryland 6 8 9 9 9 8 6 6 5 6
15Virginia 10 19 22 28 22 21 15 13 8 9
North Carolina 5 10 12 13 13 13 9 8 7 8
South
5 6 8 9 9 9 7 6 4 5
Carolina
Georgia 3 2 4 6 7 9 18 8 7 9
Kentucky 2 6 10 12 13 10 10 9 10
16Tennessee 3 6 9 13 11 10 8 10
17 Ohio 6 14 19 21 21 19 20
18Louisiana 3 3 4 4 5 6
19Indiana 3 7 10 11 11 13
20Mississippi 1 2 4 5 5 6
21Illinois 1 3 7 9 14 19
22Alabama 3 5 7 7 6 8
23Missouri 2 5 7 9 13
24Michigan 3 4 6 9
25Arkansas 1 2 3 4
26Florida 1 1 2
27Iowa 2 6 9
28Texas 2 4 6
29Wisconsin 3 6 8
30California 2 3 4
31Minnesota 2 2 3
32Oregon 1 1 1
33Kansas 1 3
34West Virginia 3 3
35Nevada 1 1
36Nebraska 1 1
37Colorado

65 105 141 186 212 241 243 236 243 292

[When vacancies happen in the representation from any State the executive authority
thereof shall issue writs of election to fill such vacancies. Const. U. S., Art. I, Sec. 2.]

[No Senator or Representative shall, during the time for which he was elected, be
appointed to any civil office under the authority of the United States, which shall have
been created, or the emoluments whereof shall have been increased during such time;
and no person, holding any office under the United States, shall be a member of either
House during his continuance in office. Const. I, 6.]

SECTION VI.

QUORUM.

[A majority of each House shall constitute a quorum to do business; but a smaller


number may adjourn from day to day, and may be authorized to compel the attendance
of absent members, in such manner and under such penalties as each House may
provide. Const. I, 5.]

[In general, the chair is not to be taken till a quorum for business is present; unless,
after due waiting, such a quorum be despaired of, when the chair may be taken and the
House adjourned. And whenever, during business, it is observed that a quorum is not
present, any member may call for the House to be counted; and being found deficient,
business is suspended. 2 Hats., 125, 126.]

[The President having taken the chair, and a quorum being present, the journal of the
preceding day shall be read, to the end that any mistake may be corrected that shall
have been made in the entries. Rules of the Senate.]

SECTION VII.

CALL OF THE HOUSE.

On a call of the House, each person rises up as he is called and answereth; the
absentees are then only noted, but no excuse to be made till the House be fully called a
second time, and if still absent, excuses are to be heard. Ord. House of Commons, 92.

They rise that their persons may be recognized; the voice in such a crowd, being an
insufficient verification of their presence. But in so small a body as the Senate of the
United States, the trouble of rising cannot be necessary.

SECTION VIII.

ABSENCE.

[No member shall absent himself from the service of the Senate without leave of the
Senate first obtained. And in case a less number than a quorum of the Senate shall
convene, they are hereby authorized to send the Sergeant-at-Arms, or any other person
or persons by them authorized, for any or all absent members, as the majority of such
members present shall agree, at the expense of such absent members, respectively,
unless such excuse for non-attendance shall be made as the Senate, when a quorum is
convened, shall judge sufficient; and in that case the expense shall be paid out of the
contingent fund. And this rule shall apply as well to the first convention of the Senate, at
the legal time of meeting, as to each day of the session, after the hour is arrived to
which the Senate stood adjourned. Rule 8.]

SECTION IX.

SPEAKER.

[The Vice-President of the United States shall be President of the Senate, but shall have
no vote unless they be equally divided. Constitution, I, 3.]

[The Senate shall choose their officers, and also a President pro tempore in the absence
of the Vice-President, or when he shall exercise the office of President of the United
States. Ib.]

[The House of Representatives shall choose their Speaker and other officers. Const., I,
2.]

When but one person is proposed, and no objection made, it has not been usual in
Parliament to put any question to the House; but without a question the members
proposing him conduct him to the chair. But if there be objection, or another proposed, a
question is put by the clerk. 2 Hats., 168. As are also questions of adjournment. 6 Grey,
406. Where the House debated and exchanged messages and answers with the king for
a week, without a Speaker, till they were prorogued. They have done it de die in diem for
fourteen days. 1 Chand., 331, 335.

[In the Senate, a President pro tempore in the absence of the Vice-President is proposed
and chosen by ballot. His office is understood to be determined on the Vice-President’s
appearing and taking the chair, or at the meeting of the Senate after the first recess.]

Where the Speaker has been ill, other Speakers pro tempore have been appointed.
Instances of this are 1 H., 4. Sir John Cheyney, and for Sir Wm. Sturton, and in 15 H., 6.
Sir John Tyrrell, in 1656, January 27; 1658, March 9; 1659, January 13.

Sir Job Charlton ill, Seymour chosen,


1673, February 18.
Not merely pro tempore, 1
Seymour being ill, Sir Robert Sawyer
Chand., 169, 276, 277.
chosen, 1678, April 15.
Sawyer being ill, Seymour chosen.

Thorpe in execution, a new Speaker chosen, 31 H. VI. 3 Grey, 11; and March 14, 1694,
Sir John Trevor chosen. There have been no later instances. 2 Hats., 161; 4 Inst.; 8 E.
Parl., 263.

A Speaker may be removed at the will of the House, and a Speaker pro tempore
appointed.38 2 Grey, 186; 5 Grey, 134.

SECTION X.

ADDRESS.

[The President shall, from time to time, give to the Congress information of the State of
the Union, and recommend to their consideration such measures as he shall judge
necessary and expedient. Const., II, 3.]

A joint address of both Houses of Parliament is read by the Speaker of the House of
Lords. It may be attended by both Houses in a body, or by a committee from each
House, or by the two Speakers only. An address of the House of Commons only, may be
presented by the whole House, or by the Speaker, 9 Grey, 473; 1 Chand., 298, 301; or
by such particular members as are of the privy council. 2 Hats., 278.

SECTION XI.

COMMITTEES.

Standing committees, as of privileges and elections, etc., are usually appointed at the
first meeting, to continue through the session. The person first named is generally
permitted to act as chairman. But this is a matter of courtesy; every committee having a
right to elect their own chairman, who presides over them, puts questions, and reports
their proceedings to the House. 4 Inst., 11, 12; Scob., 9; 1 Grey, 122.

At these committees the members are to speak standing, and not sitting; though there is
reason to conjecture it was formerly otherwise. D’Ewes, 630, col. 1; 4 Parl. Hist., 440; 2
Hats., 77.

Their proceedings are not to be published, as they are of no force till confirmed by the
House. Rushw., part 3, vol. 2, 74; 3 Grey, 401; Scob., 39. Nor can they receive a petition
but through the House. 9 Grey, 412.

When a committee is charged with an inquiry, if a member prove to be involved, they


cannot proceed against him, but must make a special report to the House; whereupon
the member is heard in his place, or at the bar, or a special authority is given to the
committee to inquire concerning him. 9 Grey, 523.

So soon as the House sits, and a committee is notified of it, the chairman is in duty
bound to rise instantly, and the members to attend the service of the House. 2 Nals.,
319.
It appears that on joint committees of the Lords and Commons, each committee acted
integrally in the following instances: 7 Grey, 261, 278, 285, 338; 1 Chandler, 357, 462.
In the following instances it does not appear whether they did or not: 6 Grey, 129; 7
Grey, 213, 229, 321.39

SECTION XII.

COMMITTEE OF THE WHOLE.

The speech, message, and other matters of great concernment, are usually referred to a
committee of the whole house, (6 Grey, 311,) where general principles are digested in
the form of resolutions, which are debated and amended till they get into a shape which
meets the approbation of a majority. These being reported and confirmed by the House,
are then referred to one or more select committees, according as the subject divides
itself into one or more bills. Scob., 36, 44. Propositions for any charge on the people are
especially to be first made in a committee of the whole. 3 Hats., 127. The sense of the
whole is better taken in committee, because in all committees every one speaks as often
as he pleases. Scob., 49. They generally acquiesce in the chairman named by the
Speaker; but, as well as all other committees, have a right to elect one, some member,
by consent, putting the question. Scob., 36; 3 Grey, 301. The form of going from the
House into committee is for the Speaker, on motion, to put the question that the House
do now resolve itself into a Committee of the Whole, to take into consideration such a
matter, naming it. If determined in the affirmative, he leaves the chair and takes a seat
elsewhere, as any other member; and the person appointed chairman seats himself at
the clerk’s table. Scob., 36. Their quorum is the same as that of the House, and if a
defect happens, the chairman, on a motion and question, rises, the Speaker resumes the
chair, and the chairman can make no other report than to inform the House of the cause
of their dissolution. If a message is announced during a committee, the Speaker takes
the chair, and receives it, because the committee cannot. 2 Hats., 125, 126.

In a Committee of the Whole, the tellers, on a division, differing as to numbers, great


heats and confusion arose, and danger of a decision by the sword. The Speaker took the
chair, the mace was forcibly laid on the table: whereupon the Members retiring to their
places, the Speaker told the House “he had taken the chair without an order to bring the
House into order.” Some excepted against it; but it was generally approved, as the only
expedient to suppress the disorder. And every member was required, standing up in his
place, to engage that he would proceed no further, in consequence of what had
happened in the grand committee, which was done. 3 Grey, 128.

A Committee of the Whole being broken up in disorder, and the chair resumed by the
Speaker without an order, the House was adjourned. The next day the committee was
considered as thereby dissolved, and the subject again before the House, and it was
decided in the House, without returning into committee. 3 Grey, 130.

No previous question can be put in a committee, nor can this committee adjourn as
others may; but if their business is unfinished, they rise, on a question, the House is
resumed, and the chairman reports that the Committee of the Whole have, according to
order, had under their consideration such a matter, and have made progress therein; but
not having had time to go through the same, have directed him to ask leave to sit again.
Whereupon a question is put upon their having leave, and on the time the House will
again resolve itself into a committee. Scob., 38. But if they have gone through the
matter referred to them, a member moves that the committee may rise, and the
chairman report their proceedings to the House; which being resolved, the chairman
rises, the Speaker resumes the chair, the chairman informs him that the committee have
gone through the business referred to them, and that he is ready to make report when
the House shall think proper to receive it. If the House have time to receive it, there is
usually a cry of “Now, now,” whereupon he makes the report; but if it be late, the cry is,
“To-morrow, to-morrow,” or “Monday,” etc.; or a motion is made to that effect, and a
question put, that it be received to-morrow, etc. Scob., 38.

In other things the rules of proceedings are to be the same as in the House. Scob., 39.

SECTION XIII.

EXAMINATION OF WITNESSES.

Common fame is a good ground for the House to proceed by inquiry, and even to
accusation. Resolution House of Commons, 1 Car., 1, 1624; Rush., L. Parl., 115; 1 Grey,
16-22, 92; Grey, 21, 23, 27, 45.

Witnesses are not to be produced but where the House has previously instituted an
inquiry (2 Hats., 102), nor then are orders for their attendance given blank. 3 Grey, 51.

When any person is examined before a committee, or at the bar of the House, any
member wishing to ask the person a question, must address it to the Speaker or
chairman, who repeats the question to the person, or says to him, “You hear the
question—answer it.” But if the propriety of the question be objected to, the Speaker
directs the witness, counsel, and parties, to withdraw, for no question can be moved or
put or debated while they are there. 2 Hats., 108. Sometimes the questions are
previously settled in writing before the witness enters. Ib., 106, 107; 8 Grey, 64. The
questions asked must be entered in the journals. 3 Grey, 81. But the testimony given in
answer before the House is never written down; but before a committee it must be, for
the information of the House, who are not present to hear it. 7 Grey, 52, 334.

If either house have occasion for the presence of a person in custody of the other, they
ask the other their leave that he may be brought up to them in custody. 3 Hats., 52.

A member, in his place, gives information to the House of what he knows of any matter
under hearing at the bar. Jour. H. of C., Jan. 22, 1744-45.

Either house may request, but not demand, the attendance of a member of the other.
They are to make the request by message to the other house, and to express clearly the
purpose of attendance, that no improper subject of examination may be tendered to
him. The House then gives leave to the member to attend, if he chooses it; waiting first
to know from the member himself whether he chooses to attend, till which they do not
take the message into consideration. But when the peers are sitting as a court of
criminal judicature, they may order attendance, unless where it be a case of
impeachment by the Commons. There it is to be a request. 3 Hats., 17; 9 Grey, 306,
406; 10 Grey, 133.

Counsel are to be heard only on private, not on public bills, and on such points of law
only as the House shall direct. 10 Grey, 61.

SECTION XIV.

ARRANGEMENT OF BUSINESS.

The Speaker is not precisely bound to any rules as to what bills or other matter shall be
first taken up; but is left to his own discretion, unless the House on the question decide
to take up a particular subject. Hakew., 136.

A settled order of business is, however, necessary for the government of the presiding
person, and to restrain individual members from calling up favorite measures, or matters
under their special patronage, out of their just turn. It is useful also for directing the
discretion of the House, when they are moved to take up a particular matter, to the
prejudice of the others having priority of right to their attention in the general order of
business.

[In Senate, the bills and other papers which are in possession of the House, and in a
state to be acted on, are arranged every morning, and brought on in the following
order:]

[1. Bills ready for a second reading are read, that they may be referred to committees,
and so be put under way. But if, on their being read, no motion is made for commitment,
they are then laid on the table in the general file, to be taken up in their just turn.]

[2. After 12 o’clock, bills ready for it are put on their passage.]

[3. Reports in possession of the House, which offer grounds for a bill, are to be taken up,
that the bill may be ordered in.]

[4. Bills or other matters before the House, and unfinished on the preceding day,
whether taken up in turn or on special order, are entitled to be resumed and passed on
through their present stage.]

[5. These matters being dispatched, for preparing and expediting business, the general
file of bills and other papers is then taken up, and each article of it is brought on
according to its seniority, reckoned by the date of its first introduction to the House.
Reports on bills belong to the dates of their bills.]

[The arrangement of the business of the Senate is now as follows:]

[1. Motions previously submitted.]

[2. Reports of Committees previously made.]

[3. Bills from the House of Representatives, and those introduced on leave, which have
been read the first time, are read the second time; and if not referred to a committee,
are considered in Committee of the Whole, and proceeded with as in other cases.]

[4. After twelve o’clock, engrossed bills of the Senate, and bills of the House of
Representatives, on third reading, are put on their passage.]

[5. If the above are finished before one o’clock, the general file of bills, consisting of
those reported from committees on the second reading, and those reported from
committees after having been referred, are taken up in the order in which they were
reported to the Senate by the respective committees.]

[6. At one o’clock, if no business be pending, or if no motion be called to proceed to


other business, the special orders are called, at the head of which stands the unfinished
business of the preceding day.]

[In this way we do not waste our time in debating what shall be taken up. We do one
thing at a time; follow up a subject while it is fresh, and till it is done with, clear the
House of business gradatim as it is brought on, and prevent, to a certain degree, its
immense accumulation towards the close of the session.]

[Arrangement, however, can only take hold of matters in possession of the House. New
matter may be moved at any time when no question is before the House. Such are
original motions and reports on bills. Such are bills from the other House, which are
received at all times, and receive their first reading as soon as the question then before
the House is disposed of; and bills brought in on leave, which are read first whenever
presented. So messages from the other House respecting amendments to bills are taken
up as soon as the House is clear of a question, unless they require to be printed, for
better consideration. Orders of the day may be called for, even when another question is
before the House.]

SECTION XV.

ORDER.

[Each House may determine the rules of its proceedings; punish its members for
disorderly behavior; and, with the concurrence of two-thirds, expel a member. Const., I,
5.]
In Parliament, “Instances make order,” per Speaker Onslow. 2 Hats., 141. But what is
done only by one Parliament, cannot be called custom of Parliament; by Prynne. 1 Grey,
52.

SECTION XVI.

ORDER RESPECTING PAPERS.

The Clerk is to let no journals, records, accounts or papers, be taken from the table or
out of his custody. 2 Hats., 193, 194.

Mr. Prynne having at a Committee of the Whole amended a mistake in a bill without
order or knowledge of the committee, was reprimanded. 1 Chand., 77.

A bill being missing, the House resolved that a protestation should be made and
subscribed by the members “before Almighty God and this honorable House, that neither
myself nor any other to my knowledge have taken away, or do at this present conceal a
bill entitled,” etc. 5 Grey, 202.

After a bill is engrossed, it is put into the Speaker’s hands, and he is not to let any one
have it to look into. Town., col. 200.

SECTION XVII.

ORDER IN DEBATE.

When the Speaker is seated in his chair, every member is to sit in his place. Scob., 6; 3
Grey, 403.

When any member means to speak, he is to stand up in his place, uncovered, and to
address himself, not to the House, or any particular member, but to the speaker, who
calls him by his name, that the House may take notice who it is that speaks. Scob., 6;
D’Ewes, 487; col. 1; 2 Hats., 77; 4 Grey, 66; 8 Grey, 108. But members who are
indisposed may be indulged to speak sitting. 2 Hats., 75; 1 Grey, 143.

[In Senate, every member, when he speaks, shall address the chair, standing in his
place, and when he has finished, shall sit down. Rule 3.]

When a member stands up to speak, no question is to be put, but he is to be heard


unless the House overrules him. 4 Grey, 390; 5 Grey, 6, 143.

If two or more rise to speak nearly together, the Speaker determines who was first up,
and calls him by name; whereupon he proceeds, unless he voluntarily sits down and
gives way to the other. But sometimes the House does not acquiesce in the Speaker’s
decision, in which case the question is put, “Which member was first up?” 2 Hats., 76;
Scob., 7; D’Ewes., 434, col. 1, 2.

[In the Senate of the United States, the President’s decision is without appeal. Their rule
is in these words: When two members rise at the same time, the President shall name
the person to speak; but in all cases the member who shall first rise and address the
chair, shall speak first. Rule 5.]

No man may speak more than once on the same bill on the same day; or even on
another day, if the debate be adjourned. But if it be read more than once in the same
day, he may speak once at every reading. Co., 12, 115; Hakew., 148; Scob., 58; 2 Hats.,
75. Even a change of opinion does not give a right to be heard a second time. Smyth’s
Comw., L. 2, c. 3; Arcan Parl., 17.

[The corresponding rule of the Senate is in these words: No member shall speak more
than twice, in any one debate on the same day, without leave of the Senate. Rule 4.]

But he may be permitted to speak again to a clear matter of fact (3 Grey, 357, 416); or
merely to explain himself (2 Hats., 73) in some material part of his speech (Ib. 75); or to
the manner of words of the question, keeping himself to that only, and not traveling into
the merits of it (Memorials in Hakew., 29), or to the orders of the House, if they be
transgressed, keeping within that line, and not falling into the matter itself. Mem.
Hakew., 30, 31.

But if the Speaker rise to speak, the member standing up ought to sit down, that he may
be first heard. Town. col., 205; Hale Parl., 133; Mem. in Hakew., 30, 31. Nevertheless,
though the Speaker may of right speak to matters of order, and be first heard, he is
restrained from speaking on any other subject, except where the House have occasion
for facts within his knowledge; then he may with their leave, state the matter of fact. 3
Grey, 38.

No one is to speak impertinently or beside the question, superfluously or tediously.


Scob., 31, 33; 2 Hats., 166, 168; Hale Parl., 133.

No person is to use indecent language against the proceedings of the House; no prior
determination of which is to be reflected on by any member, unless he means to
conclude with a motion to rescind it. 2 Hats., 169, 170; Rushw., p. 3, v. 1, fol. 42. But
while a proposition under consideration is still in fieri, though it has even been reported
by a committee, reflections on it are no reflections on the House. 9 Grey, 508.

No person in speaking, is to mention a member then present by his name, but to


describe him by his seat in the House, or who spoke last, or on the other side of the
question, etc. (Mem. in Hakew., 3; Smyth’s Comw., L. 2, c. 3); nor to digress from the
matter to fall upon the person (Scob., 31; Hale Parl., 133; 2 Hats., 166) by speaking
reviling, nipping or unmanly words against a particular member. Smyth’s Comw., L. 2, c.
3. The consequences of a measure may be reprobated in strong terms; but to arraign
the motives of those who propose to advocate it, is a personality, and against order. Qui
digreditur a materia ad personam, Mr. Speaker ought to suppress. Ord. Som., 1604, Apr.
19.

[* * * When a member shall be called to order by the President or a Senator, he shall sit
down, and shall not proceed without leave of the Senate; and every question of order
shall be decided by the President, without debate, subject to an appeal to the Senate;
and the President may call for the sense of the Senate on any question of order. Rule 6.]

[No member shall speak to another or otherwise interrupt the business of the Senate, or
read any newspaper while the journals or public papers are reading, or when any
member is speaking in any debate. Rule 2.]

No one is to disturb another in his speech by hissing, coughing, spitting (6 Grey, 332;
Scob., 8; D’Ewes, 332, col. 1, 640, col. 1) speaking or whispering to another (Scob., 6;
D’Ewes, 487, col. 1); nor stand up to interrupt him (Town., col. 205; Mem. in Hakew.,
31); nor to push between the Speaker and the speaking member, nor to go across the
house (Scob., 6), or to walk up and down it, or to take books or papers from the table,
or write there. 2 Hats., 171.

Nevertheless, if a member finds that it is not the inclination of the House to hear him,
and that by conversation or any other noise they endeavor to drown his voice, it is his
most prudent way to submit to the pleasure of the House, and sit down; for it scarcely
ever happens that they are guilty of this piece of ill manners without sufficient reason, or
inattentive to a member who says anything worth their hearing. 2 Hats., 77, 78.

If repeated calls do not produce order, the Speaker may call by his name any member
obstinately persisting in irregularity; whereupon the House may require the member to
withdraw. He is then to be heard in exculpation, and to withdraw. Then the Speaker
states the offense committed, and the House considers the degree of punishment they
will inflict. 3 Hats., 167, 7, 8, 172.

For instances of assaults and affrays in the House of Commons, and the proceedings
thereon, see 1 Pet. Misc., 82; 3 Grey, 128; 4 Grey, 328; 5 Grey, 382; 6 Grey, 254; 10
Grey, 8.

Whenever warm words or an assault have passed between members, the House, for the
protection of their members, requires them to declare in their places not to prosecute
any quarrel (3 Grey, 127, 293; 5 Grey, 280); or orders them to attend the Speaker, who
is to accommodate their differences, and report to the House (3 Grey, 419); and they
are put under restraint if they refuse, or until they do. 9 Grey, 234, 312.

Disorderly words are not to be noticed till the member has finished his speech. 5 Grey,
356; 6 Grey, 60. Then the person objecting to them, and desiring them to be taken
down by the clerk at the table, must repeat them. The Speaker then may direct the clerk
to take them down in his minutes; but if he thinks them not disorderly, he delays the
direction. If the call becomes pretty general, he orders the clerk to take them down, as
stated by the objecting member. They are then part of his minutes, and when read to
the offending member, he may deny they were his words, and the House must then
decide by a question whether they are his words or not. Then the member may justify
them, or explain the sense in which he used them, or apologize. If the House is satisfied,
no further proceeding is necessary. But if two members still insist to take the sense of
the House, the member must withdraw before that question is stated, and then the
sense of the House is to be taken. 2 Hats., 199; 4 Grey, 170; 6 Grey, 59. When any
member has spoken, or other business intervenes, after offensive words spoken, they
cannot be taken notice of for censure. And this is for the common security of all, and to
prevent mistakes which must happen if words are not taken down immediately. Formerly
they might be taken down at any time the same day. 2 Hats., 196; Mem. in Hakew., 71;
3 Grey, 48; 9 Grey, 514.

Disorderly words spoken in a committee must be written down as in the House; but the
committee can only report them to the House for animadversion. 6 Grey, 46.

[The rule of the Senate says: “If the member be called to order by a senator for words
spoken, the exceptional words shall immediately be taken down in writing, that the
President may be better enabled to judge of the matter.” Rule 7.]

In Parliament, to speak irreverently or seditiously against the King, is against order.


Smyth’s Comw., L. 2, c. 3; 2 Hats., 170.

It is a breach of order in debate to notice what has been said on the same subject in the
other house, or the particular votes or majorities on it there; because the opinion of each
house should be left to its own independency, not to be influenced by the proceedings of
the other; and the quoting them might beget reflections leading to a misunderstanding
between the two houses. 8 Grey, 22.

Neither house can exercise any authority over a member or officer of the other, but
should complain to the house of which he is, and leave the punishment to them. Where
the complaint is of words disrespectfully spoken by a member of another house, it is
difficult to obtain punishment, because of the rules supposed necessary to be observed
(as to the immediate noting down of words) for the security of members. Therefore it is
the duty of the House, and more particularly of the Speaker, to interfere immediately,
and not to permit expressions to go unnoticed, which may give a ground of complaint to
the other house, and introduce proceedings and mutual accusations between the two
houses, which can hardly be terminated without difficulty and disorder. 3 Hats., 51.

No member may be present when a bill or any business concerning himself is debating;
nor is any member to speak to the merits of it till he withdraws. 2 Hats., 219. The rule
is, that if a charge against a member arise out of a report of a committee, or
examination of witnesses in the House, as the member knows from that to what points
he is to direct his exculpation, he may be heard to those points before any question is
moved or stated against him. He is then to be heard, and withdraw before any question
is moved. But if the question itself is the charge, as for breach of order, or matter arising
in the debate, then the charge must be stated, (that is, the question must be moved,)
himself heard, and then to withdraw. 2 Hats., 121, 122.
Where the private interests of a member are concerned in a bill or question, he is to
withdraw. And where such an interest has appeared, his voice has been disallowed, even
after a division. In a case so contrary, not only to the laws of decency, but to the
fundamental principle of the social compact which denies to any man to be a judge in his
own cause, it is for the honor of the House that this rule of immemorial observance,
should be strictly adhered to. 2 Hats., 119, 121; 6 Grey, 368.

No member is to come into the house with his head covered, nor to remove from one
place to another with his hat on, nor is to put on his hat in coming in or removing, until
he be set down in his place. Scob., 6.

A question of order may be adjourned to give time to look into precedents. 2 Hats., 118.

In Parliament all decisions of the Speaker may be controlled by the House. 3 Grey, 319.

SECTION XVIII.

ORDERS OF THE HOUSE.

Of right, the doors of the House ought not to be shut, but to be kept by porters, or
sergeant-at-arms, assigned for that purpose. Mod. Ten. Parl., 23.

[By the rules of the Senate, on motion made and seconded to shut the doors of the
Senate on the discussion of any business which may, in the opinion of a member, require
secrecy, the President shall direct the gallery to be cleared; and during the discussion of
such motion the doors shall remain shut. Rule 18.]

No motion shall be deemed in order to admit any person or persons whatsoever, within
the doors of the Senate chamber, to present any petition, memorial or address, or to
hear any such read. Rule 19.

[The only case where a member has a right to insist on anything, is where he calls for
the execution of a subsisting order of the House. Here, there having been already a
resolution, any person has a right to insist that the Speaker, or any other whose duty it
is, shall carry it into execution; and no debate or delay can be had on it. Thus any
member has a right to have the House or gallery cleared of strangers, an order existing
for that purpose; or to have the House told where there is not a quorum present. 2
Hats., 87, 129. How far an order of the House is binding. See Hakew., 392.]

But where an order is made that any particular matter be taken up on a particular day,
there a question is to be put, when it is called for, whether the House will now proceed
to that matter? Where orders of the day are on important or interesting matter, they
ought not to be proceeded on till an hour at which the House is usually full, [which in
Senate is at noon.]
Orders of the day may be discharged at any time, and a new one made for a different
day. 3 Grey, 48, 313.

When a session is drawing to a close, and the important bills are all brought in, the
House, in order to prevent interruption by further unimportant bills, sometimes come to
a resolution that no new bill be brought in, except it be sent from the other house. 3
Grey, 156.

All orders of the House determine with the session; and one taken under such an order
may, after the session is ended, be discharged on a habeas corpus. Raym., 120; Jacob’s
L. D. by Ruffhead; Parliament, 1 Lev., 165, (Pritchard’s case.)

[Where the Constitution authorizes each House to determine the rules of its proceedings,
it must mean in those cases (legislative, executive or judiciary) submitted to them by the
Constitution, or in something relating to these, and necessary towards their execution.
But orders and resolutions are sometimes entered in the journals, having no relation to
these, such as acceptances of invitations to attend orations, to take part in processions,
etc. These must be understood to be merely conventional among those who are willing
to participate in the ceremony, and are, therefore, perhaps, improperly placed among
the records of the House.]

SECTION XIX.

PETITIONS.

A petition prays something. A remonstrance has no prayer. 1 Grey, 58.

Petitions must be subscribed by the petitioners (Scob., 87; L. Parl., c. 22; 9 Grey, 362),
unless they are attending (1 Grey, 401); or unable to sign, and averred by a member (3
Grey, 418). But a petition not subscribed, but which the member presenting it affirmed
to be all in the handwriting of the petitioner, and his name written in the beginning, was
on the question (Mar. 14, 1800) received by the Senate. The averment of a member, or
of somebody withoutdoors, that they know the handwriting of the petitioners, is
necessary, if it be questioned (6 Grey, 36). It must be presented by a member, not by
the petitioners, and must be opened by him holding it in his hand. 10 Grey, 57.

[Before any petition or memorial addressed to the Senate shall be received and read at
the table, whether the same shall be introduced by the President or a member, a brief
statement of the contents of the petition or memorial shall verbally be made by the
introducer. Rule 24.]

Regularly, a motion for receiving it must be made and seconded, and a question put,
whether it shall be received? But a cry from the House of “Received,” or even its silence,
dispenses with the formality of this question; it is then to be read at the table, and
disposed of.
SECTION XX.

MOTIONS.

When a motion has been made it is not to be put to the question, or debated until it is
seconded. Scob., 21.

[The Senate say: No motion shall be debated until the same shall be seconded. Rule 9.]

It is then, and not till then, in possession of the House, and cannot be withdrawn but by
leave of the House. It is to be put into writing, if the House or Speaker require it, and
must be read to the House by the Speaker as often as any member desires it for his
information. 2 Hats., 82.

[The rule of the Senate is: When a motion shall be made and seconded, it shall be
reduced to writing, if desired by the President or any member, delivered in at the table,
and read, before the same shall be debated. * * * Rule 10.]

It might be asked, whether a motion for adjournment or for the orders of the day, can
be made by any one member while another is speaking. It cannot. When two members
offer to speak, he who rose first is to be heard; and it is a breach of order in another to
interrupt him, unless by calling him to order if he departs from it. And the question of
order being decided, he is still to be heard through. A call for adjournment, or for the
order of the day, or for the question, by gentlemen from their seats, is not a motion. No
motion can be made without arising and addressing the chair. Such calls are themselves
breaches of order, which, though the member who has risen may respect as an
expression of impatience of the House against further debate, yet, if he chooses, he has
a right to go on.

SECTION XXI.

RESOLUTIONS.

When the House commands, it is by an “order.” But facts, principles, and their own
opinions and purposes, are expressed in the form of resolutions.

[A resolution for an allowance of money to the clerks being moved, it was objected to as
not in order, and so ruled by the Chair; but on an appeal to the Senate (i. e., a call for
their sense by the President, on account of doubt in his mind, according to rule 26), the
decision was overruled, Jour. Sen., June 1, 1796. I presume the doubt was, whether an
allowance of money could be made otherwise than by bill.]

SECTION XXII.

BILLS.
[Every bill shall receive three readings previous to its being passed; and the President
shall give notice at each whether it be first, second or third; which readings shall be on
three different days, unless the Senate unanimously direct otherwise. * * * Rule 26.]

SECTION XXIII.

BILLS—LEAVE TO BRING IN.

[One day’s notice, at least, shall be given of an intended motion for leave to bring in a
bill. Rule 25.]

When a member desires to bring in a bill on any subject, he states to the House in
general terms the causes for doing it, and concludes by moving for leave to bring in a bill
entitled, etc. Leave being given on the question, a committee is appointed to prepare
and bring in the bill. The mover and seconder are always appointed of this committee,
and one or more in addition. Hakew., 122; Scob., 40.

It is to be presented fairly written, without any other erasure or interlineation, or the


Speaker may refuse it. Scob., 41; 1 Grey, 82, 84.

SECTION XXIV.

BILLS—FIRST READING.

When a bill is first presented, the clerk reads it at the table, and hands it to the Speaker,
who, rising, states to the House the title of the bill; that this is the first time of reading
it; and the question will be, whether it shall be read a second time? then sitting down to
give an opening for objections. If none be made, he rises again, and puts the question,
whether it shall be read a second time? Hakew., 137, 141. A bill cannot be amended on
the first reading, (6 Grey, 286;) nor is it usual for it to be opposed then, but it may be
done and rejected. D’Ewes, 335, col 1; 3 Hats., 198.

SECTION XXV.

BILLS—SECOND READING.

The second reading must regularly be on another day. Hakew., 143. It is done by the
Clerk at the table, who then hands it to the Speaker. The Speaker rising, states to the
House the title of the bill; that this is the second time of reading it; and that the question
will be, whether it shall be committed or engrossed and read a third time? But if the bill
came from the other House, as it always comes engrossed, he states that the question
will be, whether it shall be read a third time? and before he has so reported the state of
the bill, no one is to speak to it. Hakew., 143, 146.
[In the Senate of the United States, the President reports the title of the bill; that this is
the second time of reading it; that it is now to be considered as in a Committee of the
Whole; and the question will be, whether it shall be read a third time? or that it may be
referred to a special committee?]

SECTION XXVI.

BILLS—COMMITMENT.

If on motion and question it be decided that the bill shall be committed, it may then be
moved to be referred to Committee of the Whole House, or to a special committee. If
the latter, the Speaker proceeds to name the committee. Any member also may name a
single person, and the clerk is to write him down as of the committee. But the House
have a controlling power over the names and number, if a question be moved against
anyone; and may in any case put in and put out whom they please.

Those who take exceptions to some particulars in the bill are to be of the committee, but
none who speak directly against the body of the bill; for he that would totally destroy will
not amend it, (Hakew., 146; Town., col. 208; D’Ewes, 634, col. 2; Scob., 47;) or, as it is
said, (5 Grey, 145,) the child is not to be put to a nurse that cares not for it, (6 Grey,
373.) It is therefore a constant rule “that no man is to be employed in any matter who
has declared himself against it.” And when any member, who is against the bill, hears
himself named to its committee, he ought to ask to be excused. Thus (March 7, 1606)
Mr. Hadley was, on the question being put, excused from being of a committee,
declaring himself to be against the matter itself. Scob., 46.

[No bill shall be committed or amended until it shall have been twice read; after which it
may be referred to a committee. Rule 27.]

[In the appointment of the standing committees, the Senate will proceed, by ballot,
severally to appoint the Chairman of each committee; and then, by one ballot, the other
members necessary to complete the same; and a majority of the whole number of votes
given shall be necessary to the choice of a chairman of a standing committee. All other
committees shall be appointed by ballot, and a plurality of votes shall make a choice.
When any subject or matter shall have been referred to a committee, any other subject
or matter of a similar nature, may, on motion, be referred to such committee. Rule 34.]

The clerk may deliver the bill to any member of the committee, (Town., col. 138;) but it
is usual to deliver it to him who is first named.

In some cases the House has ordered a committee to withdraw immediately into the
Committee Chamber, and act on and bring back the bill, sitting in the House. Scob., 48.
A committee meet when and where they please, if the House has not ordered time and
place for them, (6 Grey, 370;) but they can only act when together, and not by separate
consultation and consent—nothing being the report of the committee but what has been
agreed to in committee actually assembled.

You might also like