Blazor Means Business: Enhancing Enterprise Architecture Delivery with Paul Schroeder

 
Paul Schroeder – MSC Technology Consulting
 
@PaulBSchroeder
 
RealPaulSchroeder
 
paul@msctek.com
R
a
p
i
d
 
E
n
t
e
r
p
r
i
s
e
 
A
r
c
h
i
t
e
c
t
u
r
e
 
D
e
l
i
v
e
r
y
youtube.com/watch?v=oZc1Nquxvlk
GitHub:
xamarindevelopersummit/XamDevSummit2019
X
a
m
a
r
i
n
 
D
e
v
e
l
o
p
e
r
 
S
u
m
m
i
t
 
2
0
1
9
Dedicated to K.
Scott Allen
Microsoft Regional Director and MVP
Founder of OdeToCode
Founding Pluralsight author (54 courses)
Frequent Conference Speaker
CTO, Consultant, Trainer
June 11, 1969 - January 10, 2020
“The Blazor Bet”
Tuesday, September 24, 2019
odetocode.com/blogs/scott/archive/2019/09/24/
the-blazor-bet.aspx
Head to Head: Scott Allen and Jon Skeet - Scott Hanselman
youtu.be/H2KkiRbDZyc
 
  NDC (Sydney) Aug 29, 2016
@csharpfritz
@danroth27
 
Build interactive web UIs using C#
Composed of reusable components
(C#, HTML, and CSS)
C# for both client and server code
Enables sharing of code and libraries
JavaScript – “As Needed”
A feature of ASP.NET Core
What is Blazor?
 
What is
n’t
 Blazor?
 
Smooth & Business Savvy
 
“Yeah, I remember the same WPF
hype…and WCF…and Silverlight…and
LightSwitch …and W8 Store…and….
 
 
N
o
t
 
t
h
e
 
n
e
w
 
s
h
i
n
y
!
 
Surprisingly simple
Straight forward & predictable behavior
Few surprises
Promising development experience
@
PaulBSchroeder
https://visualstudiomagazine.com/articles/2019/09/26/blazor-future.aspx
Blazor
Roadmap
 
O
c
t
 
2
0
1
9
 
M
a
y
 
2
0
2
0
 
(
n
o
t
 
L
T
S
)
 
https://aka.ms
/blazorelectron
/webwindow
blazormobile
Embed a Blazor web
app as a standalone
mobile app, hosted
in Xamarin
Deploy as a desktop
application with
Electron.NET
Welcome to Blazor - Daniel Roth
Blazor Future Features - Steve Sanderson
Routing A-Z - Chris Sainty
Create a great UX with Blazor - Jimmy Engstrom
State Management in Blazor Apps - Jeremy Likness
JavaScript Two-Way Interop - Javier Calvarro Nelson
Testing Blazor Components - Egil Hansen
Mobile Blazor Bindings – Using Blazor to build mobile
apps - Eilon Lipton 
Authoring Custom Components - Ed Charbeneau
Microsoft, Google and Cookie Authentication and
Authorization - Michael Washington
Scaling Blazor Server Apps with Azure - Ryan Nowak
Build Serverless Apps with Blazor - Daria Grigoriu
Fabio Cavalcante
Blazor for Web Form and C# Developers - Jeff Fritz
Blazor Has
Momentum
github.com/xamarin/MobileBlazorBindings
Mobile Blazor Bindings – Using Blazor to Build Mobile Apps - Eilon Lipton – 6h 29m
 
2
 
F
l
a
v
o
r
s
:
 
S
e
r
v
e
r
-
S
i
d
e
 
&
 
C
l
i
e
n
t
-
S
i
d
e
Server-Side
Blazor
ASP.NET Core
Razor Components
.NET
SignalR
 
“Server-side Blazor has the same syntax as the client-side”
“Just copy and paste your server-side code into a client-side Blazor project”
Blazor WebAssembly features for May
.NET Standard 2.1
WebSockets + .NET SignalR client
Debugging (browser dev tools & Visual Studio)
Auto-rebuild
IL trimming
Brotli compression
Static web assets integration
Authentication options
Localization
Server-
Side
Primer Demo!
Create new Blazor server-side project
Visualize the SignalR channel
Routing
State management
o
Offline capability (local storage)
Dependency injection => ConfigureServices()
Examine pipeline concept => Configure()
Vary by environment
Components – How did we get here?
Browser’s Console & Network Tabs
Pending
Sent
<h1>Weather forecast</h1>
<p>This component demonstrates
fetching data from a service</p>
table.class.table
7468  ...        ..<thead>.. <tr>..
7465          <th>Date
2020  </th>..
2020  body....
2020          .tr...
3016    .td.1/12/2020.
6c6d            .Balmy
Received
Reconnection attempts – blazor.server.js
Offline
Capability /
Local Storage
github.com/Blazored/LocalStorage
github.com/BlazorExtensions/Storage
github.com/cloudcrate/BlazorStorage
Wraps HTML5 Storage APIs. Both Session
and Local storage types are supported.
See .NET Conf 1/14/20 State Management in Blazor Apps - Jeremy Likness  4h 15m
Other Uses
for
Environment
if (
env
.IsDevelopment())
{
 
// This will push telemetry data through Application Insights
pipeline faster, allowing you to view results immediately.
        builder.AddApplicationInsightsSettings(
developerMode: true
);
}
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{
env
.EnvironmentName}.json", optional: true)
.AddJsonFile($"customSettings.json", optional: true, reloadOnChange:
true)
Control the diagnostics logging level (Debug, Info, Warning, etc.)
Send a minified version of a static file (i.e. *.css / *.js)
P
o
s
t
-
D
e
m
o
 
Q
u
i
z
Between server-side and client-side
(WebAssembly) Blazor, which will…
Have faster execution?
Loads faster, initially?
Cannot access DbContext?
Work on clients that do not
support WebAssembly?
Could be designed to work
offline?
 
WebAssembly
 because it can operate completely
independent from the Internet, once downloaded.
Dan Roth - .NET Conf
1/14/20  Welcome to
Blazor 1 h 46m
 
Giveaway for Tonight’s
CNUG Attendees
Free 1-year Subscription
Visual Studio 2019 Extension
Code Generate Enterprise Architecture Classes
Adapt to Requirements Change in Minutes
Save Time / Lower Development Cost
Eliminate Human Error Bugs (i.e. Copy / Paste)
Focus on Business Rules & UI not Plumbing
10-Minute
Intermission!
Any questions at this time?
Something you really want
to see covered in the
advanced session?
Twitter:
@_CNUG
#blazor
@PaulBSchroeder
@danroth27
@CSharpFritz
#MakeFritzProud
#AwesomePurpleBlazer
Event Portal
Unauthorized User
Event Portal
Partner Access
?
Partner Center Menu
Username Greeting
Create Event Button
Edit, Roster, Survey
# of Reservations
Event Portal
Staff Access
Analytics Menu
Review Submissions
Partner Icon
Access to All Events
Advanced
Demo Items
Routing & Navigation
Inherits & Dependency Injection
Binding (variables & properties)
Event Lifecycle
Click events
Localization – UTC vs. Local time
JavaScript Runtime
IHttpContextAccessor & Cookies
UserCultureInfo.razor
Routing &
Navigation
Use a NavLink component in place of
HTML hyperlink elements (<a>) when
creating navigation links.  Has an
“active” class feature.
Multiple route
templates can be
applied to a
component.
<Router
    AppAssembly="typeof(Program).Assembly"
    
AdditionalAssemblies
="new[] { typeof(MyCustom).Assembly }">
    ...
</Router>
App.razor - Use the AdditionalAssemblies
parameter for the Router component to
look in more places when searching for
routable components.
Programmatic: Use NavigationManager
to work with URIs and navigation in C#
code.
@page 
"/eventdetail/{eventId:int}"
Route Constraint
Date Localization
Globalization
 - design applications for multiple cultures.
Localization
 - customize for a given culture and locale.
!=
Central Standard Time
America/Chicago
Local Time Zone
Using NodaTime
Noda Time is a date and time API
acting as an alternative to the built-in
DateTime / DateTimeOffset etc. types
built into the .NET framework.
Jon Skeet
https://nodatime.org/
Convert a UTC date to local time
Persist your date fields as UTC
Field to record IANA Time
Zone Database Identifier
Event Lifecycle
Methods
OnInitialized
OnInitializedAsync
OnParametersSet
OnParametersSetAsync
OnAfterRender
OnAfterRenderAsync
ShouldRender
StateHasChanged
Synchronous as well as asynchronous
lifecycle methods are provided.
OnInitialized* are only called one time
firstRender
 - used to ensure that initialization
work is only performed once
Execute on component initialization & each
time new parameter values are specified
Return false to prevent changes
from being sent to UI
Set a breakpoint in OnParametersSetAsync() of
ConferenceEventSignUpVM.cs as you RSVP
IHttpContextAccessor
& Cookies
Discouraged for use with SignalR
SignalR - no guarantee HttpContext is available
github.com/aspnet/AspNetCore.Docs/issues/14974
github.com/dotnet/aspnetcore/issues/14878
“Works on my machine” – IIS Express Development
“I want the user’s time zone, but
that’s a 
browser
 setting and I’m on
the 
server
….”
Advanced
Demo 
Items
Structuring a solution for SoC
In-memory providers for rapid
prototyping
State Management
Parameters / Cascading Param
Layout Components / Pages
Architecture & Design Tips
Structure
Solutions for
Separation of
Concerns
S
e
r
v
i
c
e
s
:
I
n
-
M
e
m
o
r
y
 
D
a
t
a
P
r
o
v
i
d
e
r
s
Start with Interfaces and Services
IConferenceEventService and
ConferenceEventMemoryService
Create Sample Data
Use Singleton with DI not Transient
3-ish Options for
State 
Management
1.
In memory - Length of session
or connection
2.
Client cache via Local Storage
3.
Server - Thin client calling API
(then persist – i.e. DB)
4.
Ignore it
State Management in Blazor Apps - Jeremy Likness
.NET Conf 1/14/2020 - 4h 15m
github.com/jeremylikness/blazorstate
docs.microsoft.com/en-us/aspnet/core/blazor/state-management
timewarpengineering.github.io/blazor-state/
github.com/mrpmorris/blazor-fluxor
Encrypted State
Components
Self-contained .razor file  (UI)
with C# & HTML markup
Page, Dialog, Form
HTML markup and the
processing logic
Inject data or respond to
UI events
Can be nested, reused, and
shared among projects
To use a custom folder, add
the custom folder's
namespace to either the
parent component or to the
app's 
_Imports.razor
 file.
Use
<component>
tag helper
@
using
 CGH.EventPortal.Web.Components
@
using
 CGH.EventPortal.Web.Shared
or
Html
.RenderCompo
nentAsync<>
Components can be developed in a
separate project and packaged into
NuGet package
Dan Roth - .NET Conf 1/14/20 -
Welcome to Blazor 1 h 26m
StarRatings NuGet Package
P
a
r
a
m
e
t
e
r
s
@page 
"/eventdetail/{conferenceeventId:int}"
ConferenceEventSignUpVM.cs
BlazoredModal.razor
C
a
s
c
a
d
i
n
g
P
a
r
a
m
e
t
e
r
s
Blazor Layouts
Inherit from LayoutComponentBase
Component with a Razor template
Data binding & DI are supported
Body property placeholder for
content to be rendered inside the
layout.
@
Body gets replaced by the
content of the layout during
rendering
Advanced
Demo 
Items
Add Font Awesome
Material Design
Validate Forms Using EditForm
Modal Dialogs
Toast Service
Grid Component Implementation
Add Some Sizzle
Add Font
Awesome
_Host.cshtml - use one
or the other, not both
<link href="lib/font-
awesome/css/all.min.css"
rel="stylesheet" />
<script src="lib/font-
awesome/js/all.min.js">
</script>
stackoverflow.com/questions/5919753
3/how-to-add-font-awesome-to-blazor-
client-razor-component-app
Material
Design
Install MatBlazor library
via NuGet
_Imports.razor
@using MatBlazor
_Host.cshtml
<script src="_content/MatBlazor/dis
t/matBlazor.js"></script>
www.matblazor.com/
EditForm
Install MatBlazor
package via NuGet
_Imports.razor
@using MatBlazor
_Host.cshtml
<script src="_content/MatBlazor/dis
t/matBlazor.js"></script>
EditContext
<
EditForm
 
Model
="@QuarterlyReport"
OnValidSubmit
="@HandleValidSubmit">
Tracks the state of an editing process
that knows:
o
Which fields have been modified
o
Data entered
o
Whether or not the fields are valid
Modal Dialogs
Install Blazored.Modal
package via NuGet
_Imports.razor
@using Blazored
@using Blazored.Modal
@using Blazored.Modal.Services
JavaScript-free modal implementation for
Blazor and Razor Components applications
public
 
void
ConfigureServices
(
IServiceCollection
 services)
{ services.
AddBlazoredModal
(); }
Register Service
MainLayout.razor
<BlazoredModal />
_Host.cshtml
<link href="_content/Blazored.Modal/blazored-modal.css" rel="stylesheet" />
<link href="_content/<assembly>/<path to file>“…
github.com/Blazored/Modal
Toast
Notifications
Install Blazored.Toast
package via NuGet
_Imports.razor
@using Blazored.Toast
@using Blazored.Toast.Services
JavaScript-free toast library for Blazor and
Razor Components applications
public
 
void
ConfigureServices
(
IServiceCollection
 services)
{ services.
AddBlazoredToast 
(); }
Register Service
MainLayout.razor
<BlazoredToasts />
_Host.cshtml
<link href="_content/Blazored.Toast/blazored-toast.css" rel="stylesheet" />
<link href="_content/<assembly>/<path to file>“…
github.com/Blazored/Toast
Data Grid
Install GridBlazor &
GridMvcCore packages
via NuGet
_Imports.razor
@using GridBlazor.Pages
Grid component with CRUD for Blazor
(client/server-side) and ASP.NET Core MVC
public
 
void
ConfigureServices
(
IServiceCollection
 services)
{ services.
AddBlazoredToast 
(); }
Register Service
Quickstart Instructions
/blob/master/docs/blazor_server/Quick_start.md
_Host.cshtml
<link href="_content/GridBlazor/css/gridblazor.min.css" rel="stylesheet" />
 <script src="_content/GridBlazor/js/gridblazor.js"></script>
github.com/gustavnavar/Grid.Blazor
Advanced
Demo 
Items
Safe Storage of App Secrets
EF DbContext DI
Strongly-Typed Config Settings
Log Configuration – UserName
Query JSON in SQL Server
Infrastructure
Strongly –Typed
Config Settings
AppSettings.json
{ "ConnectionStrings": {
   "DefaultConnection": "“ },
       
"
AppSettings
"
: {
              "DefaultTzdbTimeZoneId":
"America/Phoenix"}}
[Inject]
protected IOptions<AppSettings>
CGHAppSettings { get; set; }
using Microsoft.Extensions.Configuration
using Microsoft.Extensions.Options;
In Startup.cs -> ConfigureServices()
services.Configure<AppSettings>(
Configuration.GetSection("AppSettings"));
// Place before UseSerilogRequestLogging to
// capture context.User.Identity.Name
app.UseMiddleware<Logging.LogUserNameMiddleware>();
// Place after UseStaticFiles to reduce the noise.
app.UseSerilogRequestLogging();
In Startup.cs -> Configure ()
[Inject]
protected ILoggerFactory
LoggerFactory { get; set; }
private void SetupLogger() {
 
Logger =
LoggerFactory.CreateLogger(this.GetType());
 
if (HttpContextAccessor.HttpContext != null)
{ Serilog.Context.LogContext.PushProperty("UserName",
HttpContextAccessor.HttpContext.User.Identity.Name); }
Logger.LogDebug("OnInitialized invoked in {typeName}",
this.GetType().Name); }
Serilog Logging
In ViewModel base class -> OnInitialized()
SELECT TOP 10 Id
,
JSON_VALUE([LogEvent], '$.Properties.SourceContext')
 AS [SourceContext]
,JSON_VALUE([LogEvent], '$.Properties.MachineName') AS MachineName
,JSON_VALUE([LogEvent], '$.Properties.EnvironmentUserName') AS
EnvironmentUserName
,JSON_VALUE([LogEvent], '$.Properties.UserName') AS UserName
,[LogEvent], [Message]
FROM [EventPortal].[dbo].[Logs]
WHERE 
ISJSON([LogEvent]) > 0
AND JSON_VALUE([LogEvent], '$.Properties.UserName') =
'staff@msctek.com'
ORDER BY JSON_VALUE([LogEvent], '$.TimeStamp') DESC
Query Structured Logs
with JSON data
{"TimeStamp":"2020-01-
13…,"Properties":{"typeName":"ConferenceEventListItem",
"SourceContext":"Web.Components.ConferenceEventListItem",…
,"MachineName":"BATMAN2",
"EnvironmentUserName":"AzureAD\\PaulSchroeder",
"UserName":"staff@msctek.com"}}
[LogEvent] JSON field in Log table
Advanced
Demo 
Items
Authentication / Authorization
Role & Policy-based Auth
Auditing Changes
Soft Deletes
SPA Authentication
Security, Auditing, & Data Sync
.NET Conf 1/14/2020 - JavaScript Two-Way Interop - Javier Calvarro Nelson
A
d
d
i
n
g
 
C
u
s
t
o
m
 
C
l
a
i
m
s
I
C
l
a
i
m
s
T
r
a
n
s
f
o
r
m
a
t
i
o
n
Provides a central transformation point to change
the specified principal. Note: this will be run on each
AuthenticateAsync call, so its safer to return a new
ClaimsPrincipal if your transformation is not
idempotent.
PartnerClaimsTransformation : IClaimsTransformation
public async Task<ClaimsPrincipal> TransformAsync(ClaimsPrincipal)
docs.microsoft.com/en-us/dotnet/api/
microsoft.aspnetcore.authentication.iclaimstransformation
Errata
IList Extension Methods
Reverse-Engineer a DB Using Pluralization
Execute a Stored Proc from EF Core
Incorporate Status Into Data Rows
Set Audit Field Values Automatically
.Net Standard and Xamarin Code Sharing
Razor-based Testing
File Upload
Browser Geolocation Service
.NET Conf 1/14/2020 - JavaScript Two-Way Interop - Javier Calvarro Nelson
.NET Conf 1/14/2020 - Testing Blazor Components - Egil Hansen
.Net Standard Projects can be shared
between Blazor and Xamarin apps
residing in the same solution.
R
e
s
o
u
r
c
e
s
Getting Started - 
https://blazor.net
PluralSight video: Jeff Fritz
“Blazor for the Web Forms Developer: DEVintersection 2019”
Free eBook => “Blazor for ASP.NET Web Forms Developers”
https://dotnet.microsoft.com/learn/aspnet/architecture
Lots of good Blog content & components
https://chrissainty.com/
Free YouTube videos - Edward Charbeneau
https://www.youtube.com/edwardcharbeneau
Aggregation of resources & tutorial links (i.e. Blazor workshop)
https://github.com/AdrienTorris/awesome-blazor
 
Paul Schroeder – MSC Technology Consulting
 
@PaulBSchroeder
 
RealPaulSchroeder
 
paul@msctek.com
Register at
CodeGenHero.com
Giveaway for Tonight’s
CNUG Attendees
Free 1-year Subscription
Slide Note
Embed
Share

Embrace the power of Blazor in driving business success with insights from Paul Schroeder at MSC Technology Consulting. Connect with the real Paul Schroeder on GitHub and explore rapid enterprise architecture delivery through initiatives like Xamarin Developers Summit 2019.

  • Blazor
  • Business
  • Enterprise Architecture
  • Paul Schroeder
  • Xamarin

Uploaded on Sep 26, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Blazor Means Business Paul Schroeder MSC Technology Consulting @PaulBSchroeder @PaulBSchroeder RealPaulSchroeder RealPaulSchroeder paul@msctek.com paul@msctek.com

  2. xamarindevelopersummit/XamDevSummit2019 GitHub: Rapid Enterprise Architecture Delivery Rapid Enterprise Architecture Delivery Xamarin Developer Summit 2019 Xamarin Developer Summit 2019 youtube.com/watch?v=oZc1Nquxvlk

  3. Dedicated to K. Scott Allen June 11, 1969 - January 10, 2020 Microsoft Regional Director and MVP Founder of OdeToCode Founding Pluralsight author (54 courses) Frequent Conference Speaker CTO, Consultant, Trainer The Blazor Bet Tuesday, September 24, 2019 odetocode.com/blogs/scott/archive/2019/09/24/ the-blazor-bet.aspx Head to Head: Scott Allen and Jon Skeet - Scott Hanselman youtu.be/H2KkiRbDZyc NDC (Sydney) Aug 29, 2016

  4. What is Blazor? A feature of ASP.NET Core Build interactive web UIs using C# Composed of reusable components (C#, HTML, and CSS) C# for both client and server code Enables sharing of code and libraries @csharpfritz @danroth27 JavaScript As Needed

  5. What isnt Blazor? Yeah, I remember the same WPF hype and WCF and Silverlight and LightSwitch and W8 Store and . Not the new shiny ! Not the new shiny ! Smooth & Business Savvy Surprisingly simple Straight forward & predictable behavior Few surprises Promising development experience @ @PaulBSchroeder PaulBSchroeder

  6. Oct 2019 Oct 2019 Blazor Roadmap May 2020 (not LTS) May 2020 (not LTS) https://aka.ms /blazorelectron /webwindow blazormobile Embed a Blazor web app as a standalone mobile app, hosted in Xamarin Deploy as a desktop application with Electron.NET https://visualstudiomagazine.com/articles/2019/09/26/blazor-future.aspx

  7. Welcome to Blazor - Daniel Roth Blazor Future Features - Steve Sanderson Routing A-Z - Chris Sainty Create a great UX with Blazor - Jimmy Engstrom State Management in Blazor Apps - Jeremy Likness JavaScript Two-Way Interop - Javier Calvarro Nelson Testing Blazor Components - Egil Hansen Mobile Blazor Bindings Using Blazor to build mobile apps - Eilon Lipton Authoring Custom Components - Ed Charbeneau Microsoft, Google and Cookie Authentication and Authorization - Michael Washington Scaling Blazor Server Apps with Azure - Ryan Nowak Build Serverless Apps with Blazor - Daria Grigoriu Fabio Cavalcante Blazor for Web Form and C# Developers - Jeff Fritz Blazor Has Momentum

  8. github.com/xamarin/MobileBlazorBindings

  9. Mobile Blazor Bindings Using Blazor to Build Mobile Apps - Eilon Lipton 6h 29m

  10. 2 Flavors: Server Server- -Side Side & Client Client- -Side Side Server-Side Client-Side Limited Debugging Limited Debugging Full Debugging Full Debugging ASP.NET Core Blazor Blazor Razor Components Razor Components DOM .NET (Mono) DOM .NET WebAssembly SignalR Server-side Blazor has the same syntax as the client-side Just copy and paste your server-side code into a client-side Blazor project Independently runs on client device Compiles to binary Wasm = improved performance Network latency => slower Reduced scalability => Memory

  11. Blazor WebAssembly features for May .NET Standard 2.1 WebSockets + .NET SignalR client Debugging (browser dev tools & Visual Studio) Auto-rebuild IL trimming Brotli compression Static web assets integration Authentication options Localization

  12. Create new Blazor server-side project Visualize the SignalR channel Routing State management Server-Side o Offline capability (local storage) Dependency injection => ConfigureServices() Primer Demo! Examine pipeline concept => Configure() Vary by environment Components How did we get here?

  13. Browsers Console & Network Tabs Pending

  14. Sent Received <h1>Weather forecast</h1> <p>This component demonstrates fetching data from a service</p> table.class.table 7468 ... ..<thead>.. <tr>.. 7465 <th>Date 2020 </th>.. 2020 body.... 2020 .tr... 3016 .td.1/12/2020. 6c6d .Balmy

  15. Reconnection attempts blazor.server.js

  16. Offline Capability / Local Storage Wraps HTML5 Storage APIs. Both Session and Local storage types are supported. github.com/Blazored/LocalStorage github.com/BlazorExtensions/Storage github.com/cloudcrate/BlazorStorage See .NET Conf 1/14/20 State Management in Blazor Apps - Jeremy Likness 4h 15m

  17. if (env.IsDevelopment()) { // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately. builder.AddApplicationInsightsSettings(developerMode: true); } Other Uses for Environment .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddJsonFile($"customSettings.json", optional: true, reloadOnChange: true) Control the diagnostics logging level (Debug, Info, Warning, etc.) Send a minified version of a static file (i.e. *.css / *.js)

  18. Between server-side and client-side (WebAssembly) Blazor, which will Post Post- -Demo Quiz Demo Quiz WebAssembly because it does not have the network latency associated with the SignalR messaging channel Have faster execution? Server-side because it does not have the large download size associated with a .NET Mono runtime (~ 2MB) Loads faster, initially? WebAssembly Even w/C#, Wasm DLLs cannot do anything JavaScript cannot do use API & services instead! Cannot access DbContext? Dan Roth - .NET Conf 1/14/20 Welcome to Blazor 1 h 46m Server-side because that is where the component code executes also best for thin/resource-constrained clients. Work on clients that do not support WebAssembly? Could be designed to work offline? WebAssembly because it can operate completely independent from the Internet, once downloaded.

  19. Giveaway for Tonights CNUG Attendees Free 1-year Subscription Register at CodeGenHero.com Visual Studio 2019 Extension Code Generate Enterprise Architecture Classes Adapt to Requirements Change in Minutes Save Time / Lower Development Cost Eliminate Human Error Bugs (i.e. Copy / Paste) Focus on Business Rules & UI not Plumbing

  20. Any questions at this time? Something you really want to see covered in the advanced session? 10-Minute Intermission! Twitter: @_CNUG #blazor @PaulBSchroeder @danroth27 @CSharpFritz #MakeFritzProud #AwesomePurpleBlazer

  21. Event Portal Unauthorized User Limited Menu Options Register & Log In Buttons RSVP & More Details

  22. Event Portal Partner Access Partner Center Menu Username Greeting Create Event Button Edit, Roster, Survey # of Reservations ?

  23. Event Portal Staff Access Analytics Menu Review Submissions Partner Icon Access to All Events

  24. UserCultureInfo.razor Routing & Navigation Inherits & Dependency Injection Binding (variables & properties) Advanced Demo Items Event Lifecycle Click events Localization UTC vs. Local time JavaScript Runtime IHttpContextAccessor & Cookies

  25. Multiple route templates can be applied to a component. Routing & Navigation Use a NavLink component in place of HTML hyperlink elements (<a>) when creating navigation links. Has an active class feature. App.razor - Use the AdditionalAssemblies parameter for the Router component to look in more places when searching for routable components. Route Constraint @page "/eventdetail/{eventId:int}" Programmatic: Use NavigationManager to work with URIs and navigation in C# code. <Router AppAssembly="typeof(Program).Assembly" AdditionalAssemblies="new[] { typeof(MyCustom).Assembly }"> ... </Router>

  26. SO 2013: How to translate between Windows and IANA time zones? Those provided by Microsoft for use with Windows and the .NET TimeZoneInfo class are identified by a value such as "Eastern Standard Time". Those provided by IANA in the TZDB, and used by the .NET TimeZoneInfo class when running on Linux or OSX, are identified by a value such as "America/New_York". const tz = Intl.DateTimeFormat().resolvedOptions().timeZone; console.log(tz); != Central Standard Time America/Chicago Date Localization Globalization - design applications for multiple cultures. Localization - customize for a given culture and locale.

  27. Convert a UTC date to local time Field to record IANA Time Zone Database Identifier Persist your date fields as UTC Noda Time is a date and time API acting as an alternative to the built-in DateTime / DateTimeOffset etc. types built into the .NET framework. Local Time Zone Using NodaTime Jon Skeet https://nodatime.org/

  28. Event Lifecycle Methods Synchronous as well as asynchronous lifecycle methods are provided. Set a breakpoint in OnParametersSetAsync() of ConferenceEventSignUpVM.cs as you RSVP OnInitialized* are only called one time Execute on component initialization & each time new parameter values are specified OnInitialized OnInitializedAsync OnParametersSet OnParametersSetAsync OnAfterRender OnAfterRenderAsync ShouldRender StateHasChanged firstRender - used to ensure that initialization work is only performed once Return false to prevent changes from being sent to UI

  29. I want the users time zone, but that s a browsersetting and I m on the server . IHttpContextAccessor & Cookies Discouraged for use with SignalR SignalR - no guarantee HttpContext is available github.com/aspnet/AspNetCore.Docs/issues/14974 github.com/dotnet/aspnetcore/issues/14878 Works on my machine IIS Express Development

  30. Architecture & Design Tips Structuring a solution for SoC In-memory providers for rapid prototyping State Management Parameters / Cascading Param Layout Components / Pages Advanced Demo Items

  31. Structure Solutions for Separation of Concerns

  32. Start with Interfaces and Services IConferenceEventService and ConferenceEventMemoryService Create Sample Data Use Singleton with DI not Transient Services: Services: In In- -Memory Data Memory Data Providers Providers

  33. State Management in Blazor Apps - Jeremy Likness .NET Conf 1/14/2020 - 4h 15m 3-ish Options for State Management github.com/jeremylikness/blazorstate 1. In memory - Length of session or connection Client cache via Local Storage Server - Thin client calling API (then persist i.e. DB) Ignore it 2. 3. 4. Encrypted State docs.microsoft.com/en-us/aspnet/core/blazor/state-management timewarpengineering.github.io/blazor-state/ github.com/mrpmorris/blazor-fluxor

  34. Self-contained .razor file (UI) with C# & HTML markup Page, Dialog, Form HTML markup and the processing logic Inject data or respond to UI events Can be nested, reused, and shared among projects Use <component> tag helper Components Components can be developed in a separate project and packaged into NuGet package or Html .RenderCompo nentAsync<> Dan Roth - .NET Conf 1/14/20 - Welcome to Blazor 1 h 26m StarRatings NuGet Package To use a custom folder, add the custom folder's namespace to either the parent component or to the app's _Imports.razor file. @using CGH.EventPortal.Web.Components @using CGH.EventPortal.Web.Shared

  35. @page "/eventdetail/{conferenceeventId:int}" Parameters Parameters BlazoredModal.razor Cascading Cascading Parameters Parameters ConferenceEventSignUpVM.cs

  36. Blazor Layouts Inherit from LayoutComponentBase Component with a Razor template Data binding & DI are supported Body property placeholder for content to be rendered inside the layout. @Body gets replaced by the content of the layout during rendering

  37. Add Some Sizzle Add Font Awesome Material Design Validate Forms Using EditForm Modal Dialogs Toast Service Grid Component Implementation Advanced Demo Items

  38. Add Font Awesome _Host.cshtml - use one or the other, not both stackoverflow.com/questions/5919753 3/how-to-add-font-awesome-to-blazor- client-razor-component-app <link href="lib/font- awesome/css/all.min.css" rel="stylesheet" /> <script src="lib/font- awesome/js/all.min.js"> </script>

  39. Material Design Install MatBlazor library via NuGet _Imports.razor @using MatBlazor _Host.cshtml <script src="_content/MatBlazor/dis t/matBlazor.js"></script> www.matblazor.com/

  40. EditContext Tracks the state of an editing process that knows: oWhich fields have been modified oData entered oWhether or not the fields are valid EditForm Install MatBlazor package via NuGet <EditFormModel="@QuarterlyReport" OnValidSubmit="@HandleValidSubmit"> _Imports.razor @using MatBlazor _Host.cshtml <script src="_content/MatBlazor/dis t/matBlazor.js"></script>

  41. JavaScript-free modal implementation for Blazor and Razor Components applications Modal Dialogs Register Service public void ConfigureServices(IServiceCollection services) { services.AddBlazoredModal(); } Install Blazored.Modal package via NuGet MainLayout.razor <BlazoredModal /> _Imports.razor @using Blazored _Host.cshtml <link href="_content/Blazored.Modal/blazored-modal.css" rel="stylesheet" /> <link href="_content/<assembly>/<path to file> @using Blazored.Modal @using Blazored.Modal.Services github.com/Blazored/Modal

  42. JavaScript-free toast library for Blazor and Razor Components applications Toast Notifications Register Service github.com/Blazored/Toast public void ConfigureServices(IServiceCollection services) { services.AddBlazoredToast (); } Install Blazored.Toast package via NuGet MainLayout.razor <BlazoredToasts /> _Imports.razor @using Blazored.Toast _Host.cshtml <link href="_content/Blazored.Toast/blazored-toast.css" rel="stylesheet" /> <link href="_content/<assembly>/<path to file> @using Blazored.Toast.Services

  43. Grid component with CRUD for Blazor (client/server-side) and ASP.NET Core MVC Data Grid Register Service public void ConfigureServices(IServiceCollection services) { services.AddBlazoredToast (); } Install GridBlazor & GridMvcCore packages via NuGet Quickstart Instructions /blob/master/docs/blazor_server/Quick_start.md _Imports.razor @using GridBlazor.Pages _Host.cshtml <link href="_content/GridBlazor/css/gridblazor.min.css" rel="stylesheet" /> <script src="_content/GridBlazor/js/gridblazor.js"></script> github.com/gustavnavar/Grid.Blazor

  44. Infrastructure Safe Storage of App Secrets EF DbContext DI Strongly-Typed Config Settings Log Configuration UserName Query JSON in SQL Server Advanced Demo Items

  45. Strongly Typed Config Settings using Microsoft.Extensions.Configuration using Microsoft.Extensions.Options; In Startup.cs -> ConfigureServices() services.Configure<AppSettings>( Configuration.GetSection("AppSettings")); AppSettings.json { "ConnectionStrings": { "DefaultConnection": " }, "AppSettings": { "DefaultTzdbTimeZoneId": "America/Phoenix"}} [Inject] protected IOptions<AppSettings> CGHAppSettings { get; set; }

  46. In Startup.cs -> Configure () // Place before UseSerilogRequestLogging to // capture context.User.Identity.Name app.UseMiddleware<Logging.LogUserNameMiddleware>(); // Place after UseStaticFiles to reduce the noise. app.UseSerilogRequestLogging(); Serilog Logging In ViewModel base class -> OnInitialized() private void SetupLogger() { LoggerFactory.CreateLogger(this.GetType()); Logger = if (HttpContextAccessor.HttpContext != null) { Serilog.Context.LogContext.PushProperty("UserName", HttpContextAccessor.HttpContext.User.Identity.Name); } [Inject] protected ILoggerFactory LoggerFactory { get; set; } Logger.LogDebug("OnInitialized invoked in {typeName}", this.GetType().Name); }

  47. {"TimeStamp":"2020-01- 13 ,"Properties":{"typeName":"ConferenceEventListItem", "SourceContext":"Web.Components.ConferenceEventListItem", ,"MachineName":"BATMAN2", "EnvironmentUserName":"AzureAD\\PaulSchroeder", "UserName":"staff@msctek.com"}} [LogEvent] JSON field in Log table Query Structured Logs with JSON data SELECT TOP 10 Id ,JSON_VALUE([LogEvent], '$.Properties.SourceContext') AS [SourceContext] ,JSON_VALUE([LogEvent], '$.Properties.MachineName') AS MachineName ,JSON_VALUE([LogEvent], '$.Properties.EnvironmentUserName') AS EnvironmentUserName ,JSON_VALUE([LogEvent], '$.Properties.UserName') AS UserName ,[LogEvent], [Message] FROM [EventPortal].[dbo].[Logs] WHERE ISJSON([LogEvent]) > 0 AND JSON_VALUE([LogEvent], '$.Properties.UserName') = 'staff@msctek.com' ORDER BY JSON_VALUE([LogEvent], '$.TimeStamp') DESC

Related


More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#