0% found this document useful (0 votes)
12 views18 pages

Building Single Page Applications in Net Core 3 Jumpstart Coding Using Blazor and C 1st Edition Michele Aponte PDF Download

Ebook

Uploaded by

ethierendry
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
0% found this document useful (0 votes)
12 views18 pages

Building Single Page Applications in Net Core 3 Jumpstart Coding Using Blazor and C 1st Edition Michele Aponte PDF Download

Ebook

Uploaded by

ethierendry
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/ 18

Building Single Page Applications In Net Core 3

Jumpstart Coding Using Blazor And C 1st Edition


Michele Aponte download

https://ebookbell.com/product/building-single-page-applications-
in-net-core-3-jumpstart-coding-using-blazor-and-c-1st-edition-
michele-aponte-50195824

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Building Single Page Applications In Net Core 3 Jumpstart Coding Using


Blazor And C 1st Edition Michele Aponte

https://ebookbell.com/product/building-single-page-applications-in-
net-core-3-jumpstart-coding-using-blazor-and-c-1st-edition-michele-
aponte-51086148

Java Ee 8 And Angular A Practical Guide To Building Modern Singlepage


Applications With Angular And Java Ee Prashant Padmanabhan

https://ebookbell.com/product/java-ee-8-and-angular-a-practical-guide-
to-building-modern-singlepage-applications-with-angular-and-java-ee-
prashant-padmanabhan-23272324

Java Ee 8 And Angular A Practical Guide To Building Modern Singlepage


Applications With Angular And Java Ee Padmanabhan

https://ebookbell.com/product/java-ee-8-and-angular-a-practical-guide-
to-building-modern-singlepage-applications-with-angular-and-java-ee-
padmanabhan-55591820

Building Spas With Django And Html Over The Wire Learn To Build
Realtime Single Page Applications With Python 1st Edition Andros
Fenollosa

https://ebookbell.com/product/building-spas-with-django-and-html-over-
the-wire-learn-to-build-realtime-single-page-applications-with-
python-1st-edition-andros-fenollosa-44868684
Building Web Applications With Vuejs Mvvm Patterns For Conventional
And Singlepage Websites Ralph Steyer

https://ebookbell.com/product/building-web-applications-with-vuejs-
mvvm-patterns-for-conventional-and-singlepage-websites-ralph-
steyer-44898498

Building Singlepage Web Apps With Meteor Fabian Vogelsteller

https://ebookbell.com/product/building-singlepage-web-apps-with-
meteor-fabian-vogelsteller-5034984

Building A Web App With Blazor And Aspnet Core Create A Single Page
App With Blazor Server And Entity Framework Jignesh Trivedi

https://ebookbell.com/product/building-a-web-app-with-blazor-and-
aspnet-core-create-a-single-page-app-with-blazor-server-and-entity-
framework-jignesh-trivedi-44888856

Design To Manufacture Of Complex Building Envelopes Single Layer


Envelopes Mulliontransom Systems 3d Printed Metal Nodes 1st Ed Alamir
Mohsen

https://ebookbell.com/product/design-to-manufacture-of-complex-
building-envelopes-single-layer-envelopes-mulliontransom-
systems-3d-printed-metal-nodes-1st-ed-alamir-mohsen-11858102

Mgtow Building Wealth And Power For Single Men Only Tim Patten

https://ebookbell.com/product/mgtow-building-wealth-and-power-for-
single-men-only-tim-patten-35127344
Building Single
Page Applications
in .NET Core 3
Jumpstart Coding Using
Blazor and C#

Michele Aponte

www.allitebooks.com
Building Single Page
Applications in
.NET Core 3
Jumpstart Coding Using
Blazor and C#

Michele Aponte

www.allitebooks.com
Building Single Page Applications in .NET Core 3: Jumpstart Coding
Using Blazor and C#

Michele Aponte
Torre del Greco (NA), Italy

ISBN-13 (pbk): 978-1-4842-5746-3 ISBN-13 (electronic): 978-1-4842-5747-0


https://doi.org/10.1007/978-1-4842-5747-0

Copyright © 2020 by Michele Aponte


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.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Joan Murray
Development Editor: Laura Berendons
Coordinating Editor: Jill Balzano
Cover image designed by Freepik (www.freepik.com)
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/
9781484257463.For more detailed information, please visit www.apress.com/source-code.
Printed on acid-free paper

www.allitebooks.com
To my son, Francesco Paolo: I hope that one day you will
read this book and be as proud of me as I am of you,
especially every time you smile when you catch my eye.

www.allitebooks.com
Table of Contents
About the Author��������������������������������������������������������������������������������vii
Acknowledgments�������������������������������������������������������������������������������ix
Introduction�����������������������������������������������������������������������������������������xi

Chapter 1: The Case for Blazor�������������������������������������������������������������1


Why You Fear JavaScript���������������������������������������������������������������������������������������2
Code Nightmares��������������������������������������������������������������������������������������������������3
Mitigate the Problem with TypeScript�������������������������������������������������������������������5
Why You Need a JavaScript Framework���������������������������������������������������������������6
You Can Have Your Cake and Eat It Too with Blazor����������������������������������������������7
Your First Blazor Application���������������������������������������������������������������������������������9
What You Need to Get Started�������������������������������������������������������������������������9
Getting Started����������������������������������������������������������������������������������������������10
Summary������������������������������������������������������������������������������������������������������������16

Chapter 2: Blazor Server vs. Blazor WebAssembly����������������������������19


How the Countdown Application Works��������������������������������������������������������������19
Running the Countdown Application in the Browser�������������������������������������������23
WebAssembly Revolution������������������������������������������������������������������������������������28
Which Blazor to Choose��������������������������������������������������������������������������������������30
Summary������������������������������������������������������������������������������������������������������������31

www.allitebooks.com
Table of Contents

Chapter 3: Create Your Single-­Page Application��������������������������������33


Everything Is a Component���������������������������������������������������������������������������������34
Component Tree���������������������������������������������������������������������������������������������35
Component Size��������������������������������������������������������������������������������������������35
Reusability, Customization, and Independence���������������������������������������������36
Component Logic�������������������������������������������������������������������������������������������38
Creating the Application Structure����������������������������������������������������������������������38
The Main Menu Component���������������������������������������������������������������������������42
Page Navigation with Blazor��������������������������������������������������������������������������47
Managing CRUD Operations��������������������������������������������������������������������������������52
Creating a CRUD Service�������������������������������������������������������������������������������55
Implementing CRUD Services�����������������������������������������������������������������������������60
Where to Place the Component Code������������������������������������������������������������������64
JavaScript Interoperability����������������������������������������������������������������������������������66
Summary������������������������������������������������������������������������������������������������������������70

Chapter 4: Build Your Reusable Blazor Library�����������������������������������73


Creating a Component Library����������������������������������������������������������������������������74
Creating a Templated Component�����������������������������������������������������������������������78
Creating a Generic Component���������������������������������������������������������������������������80
Creating Custom Input Components�������������������������������������������������������������������83
Summary������������������������������������������������������������������������������������������������������������88

Chapter 5: Deploy Your Application����������������������������������������������������91


Deploying a Blazor Server App����������������������������������������������������������������������������91
Deploying a Blazor WebAssembly App����������������������������������������������������������������97
Summary������������������������������������������������������������������������������������������������������������99

Index�������������������������������������������������������������������������������������������������101

vi
About the Author
Michele Aponte is a programmer who has worked with Java, .NET, and
JavaScript at software and IT consulting companies in his native Italy
since 1993. Combining his training, consulting, and development skills,
in 2013 Michele founded Blexin to help customers migrate older software
and systems to new technologies to improve their businesses. Passionate
about programming, Michele embraces sharing with the community.
He founded DotNetCampania, a Microsoft User Group in 2008, and
has organized many regional conferences. He is also the founder of
Blazor Developer Italiani, the Italian developer group about the Blazor
framework. Recognized as a Microsoft MVP, he often presents on Microsoft
and JavaScript topics at tech conferences throughout Italy.

vii
Acknowledgments
Writing a book is hard work that requires a lot of time and inevitably
involves the lives of those closest to the author. I want to thank my life
partner, Raffaella, for her support for this project and her patience with me.
I also want to thank my old friend, whose name is Raffaella as well, for the
help she gave me in revising my English.
A special thanks also goes to all the employees of Blexin, my company,
who are the best team one could have and with whom I can experiment
every day with the technologies described in this book.
Finally, many thanks to the fantastic Apress team that supported me
during this project.

ix
Introduction
Blazor has garnered a great deal of enthusiasm since its initial release. I’ve
followed the framework from the beginning, and when teaching any new
technology, I use a practical approach. This book looks at the needs of real
applications and answers all the questions you might have when learning
how to use Blazor.
Specifically, in Chapter 1, I focus on the success of this framework and
how it solves one of the problems most felt by Microsoft programmers:
using JavaScript. Blazor allows you to use .NET directly in the browser,
using open standards so as not to repeat the mistakes of the past. In my
opinion, however, it is important to understand how Blazor works beyond
the tools made available by the development environment, so I focus on
the code in this book. I start with a simple example, without using the
templates made available by Microsoft, to highlight how it works.
In Chapter 2, you will find a detailed comparison between the
two versions of Blazor for web development: Blazor Server and Blazor
WebAssembly. Using the example from the first chapter, I compare the
two versions by highlighting what is going on behind the scenes and how
WebAssembly is revolutionizing the world of front-end development. I
explain how to choose a version based your requirements because they
both have pros and cons and must be contextualized in your environment/
situation.
In Chapter 3, I cover all the concepts necessary to create a single-page
application, starting from scratch and tackling some issues concerning
the decomposition of the interface into components. In this chapter, you
will learn how to create pages and navigate between them, you will see
how to create forms for data entry, and you will learn how to integrate the

xi
Introduction

front end with the back-end, differentiating the approach between the
two versions of the framework but standardizing their use thanks to the
dependency injection of ASP.NET Core. Here you will discover that the
framework allows you to invoke JavaScript functions from .NET and to
invoke .NET methods from JavaScript functions.
In Chapter 4, I explain how to create libraries of reusable components,
addressing how to generalize components thanks to the framework’s
ability to use .NET Generics and content projection. What may seem
like more advanced aspects are actually necessary to avoid reinventing
the wheel on each page of your application; this also allows you to start
creating your own Blazor component library.
In Chapter 5, I cover application deployment, using both versions of
the framework. It’s important to know where your application will run,
since scalability problems must be addressed and will impact how you
write the application.
You can find the code for the first two chapters of the book in the
countdown and countdown-wasm folders of the code download; you can use
the two versions to see the differences between Blazor Server and Blazor
WebAssembly within the same small application. The code for the third
and fourth chapters, where you learn to create a small article manager, is
available for both versions of the framework in eight pieces that follow the
flow of the chapters.

• The application structure

• Pages and routing

• Components and their use in pages

• Back-end integration and shared library

• JavaScript interoperability

xii
Introduction

• Separation of the code into different files

• Blazor Library

• Custom input component

You can copy and execute the code that accompanies the book, but
I suggest you write it from scratch by following the instructions in the
chapters. That’s the best way to learn Blazor!

xiii
Random documents with unrelated
content Scribd suggests to you:
back
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like