WEBVTT
00:00:00.000 --> 00:00:01.650
>> In this episode
of the On .NET Show,
00:00:01.650 --> 00:00:02.760
we're going to have Jeffrey Fritz
00:00:02.760 --> 00:00:04.230
coming on to talk
to us about some of
00:00:04.230 --> 00:00:05.430
the new features
that are available
00:00:05.430 --> 00:00:08.170
today in ASP.NET Web Forms.
00:00:18.340 --> 00:00:22.010
Welcome to another episode
of On .NET Show and today,
00:00:22.010 --> 00:00:24.345
I have Jeff Fritz on.
How are you doing, Jeff?
00:00:24.345 --> 00:00:26.020
>> Hey, it's good
to see you, Cecil.
00:00:26.020 --> 00:00:27.545
I'm doing well.
00:00:27.545 --> 00:00:29.700
>> That's pretty good, man.
So glad to have you on.
00:00:29.700 --> 00:00:31.370
So, for our guests that don't
00:00:31.370 --> 00:00:32.970
know who you are and
what exactly you do,
00:00:32.970 --> 00:00:34.640
why don't you give us
a little bit about,
00:00:34.640 --> 00:00:36.360
let us know what you
do here at Microsoft?
00:00:36.360 --> 00:00:40.080
>> Sure. So, I'm a Program
Manager on the .NET team.
00:00:40.080 --> 00:00:42.820
I'm focused primarily on
community interaction,
00:00:42.820 --> 00:00:44.990
I do a lot of work with
Web Forms and some of
00:00:44.990 --> 00:00:48.030
our other Web
application frameworks.
00:00:48.030 --> 00:00:50.905
So, I help coordinate events,
00:00:50.905 --> 00:00:53.630
speak at a couple of events.
It's a pretty good time.
00:00:53.630 --> 00:00:54.825
>> That's pretty cool.
00:00:54.825 --> 00:00:56.390
So you mentioned Web Forms,
00:00:56.390 --> 00:00:59.370
and I know we have ASP.NET MVC.
00:00:59.370 --> 00:01:00.840
We have ASP.NET Core.
00:01:00.840 --> 00:01:03.840
We haven't been hearing too
much about Web Forms lately.
00:01:03.840 --> 00:01:05.180
Are we still working on that?
00:01:05.180 --> 00:01:06.700
Are we still creating, doing
00:01:06.700 --> 00:01:08.520
more updates and releases for it?
00:01:08.520 --> 00:01:10.245
>> Oh yes, absolutely.
00:01:10.245 --> 00:01:12.930
So, Web Forms, that's the old
00:01:12.930 --> 00:01:16.830
ASP.NET we've had since
the very beginning,
00:01:16.830 --> 00:01:18.965
where you have those ASP X Files,
00:01:18.965 --> 00:01:21.610
ASC X user controls
hanging out there.
00:01:21.610 --> 00:01:23.930
Well, we're continuing to
00:01:23.930 --> 00:01:26.645
develop and deploy
new features for that
00:01:26.645 --> 00:01:28.940
with the system Web capabilities
00:01:28.940 --> 00:01:31.725
right that DLL that ships
with .NET Framework,
00:01:31.725 --> 00:01:34.575
that everybody has on
their Windows machines.
00:01:34.575 --> 00:01:37.770
So, it's a pretty
complete framework,
00:01:37.770 --> 00:01:39.560
but we are making updates
00:01:39.560 --> 00:01:41.420
to make sure that it's
easy for folks to
00:01:41.420 --> 00:01:44.300
use with modern Web capabilities
00:01:44.300 --> 00:01:46.820
and to also give
them some routes,
00:01:46.820 --> 00:01:49.145
so they can take advantage of
00:01:49.145 --> 00:01:51.470
migration strategies to get into
00:01:51.470 --> 00:01:54.485
a .NET Core world if that's
where they want to get to.
00:01:54.485 --> 00:01:55.800
>> Great, that
sounds pretty good.
00:01:55.800 --> 00:01:57.860
So, you're actually here
to talk about some of
00:01:57.860 --> 00:01:59.240
those new features of Web Forms
00:01:59.240 --> 00:02:00.985
that we recently put out right?
00:02:00.985 --> 00:02:04.100
>> Yeah, absolutely. There were
00:02:04.100 --> 00:02:06.810
a couple of small things that
we put out in .NET Framework
00:02:06.810 --> 00:02:08.660
4.7.1 and we put out
00:02:08.660 --> 00:02:10.430
another one or two
updates that are
00:02:10.430 --> 00:02:13.070
interesting in .NET
Framework 4.7.2.
00:02:13.070 --> 00:02:15.335
So, for folks that have
the latest versions
00:02:15.335 --> 00:02:16.890
of the .NET Framework,
00:02:16.890 --> 00:02:19.760
you'll see these features both in
00:02:19.760 --> 00:02:21.560
your Visual Studio
developer packs
00:02:21.560 --> 00:02:23.140
and on the server for you.
00:02:23.140 --> 00:02:24.500
>> Cool. Sounds pretty good.
00:02:24.500 --> 00:02:28.130
So, let's talk about
configuration builders.
00:02:28.130 --> 00:02:30.210
I've seen some conversations
00:02:30.210 --> 00:02:31.715
about that and
blog post about it,
00:02:31.715 --> 00:02:33.240
but what exactly is it and
00:02:33.240 --> 00:02:34.970
what's the problem that's
it's trying to solve?
00:02:34.970 --> 00:02:37.770
>> Sure. It's
a good question, Cecil.
00:02:37.770 --> 00:02:39.330
So, what we ran into
00:02:39.330 --> 00:02:44.220
is particularly as we saw
.NET Core be released.
00:02:44.220 --> 00:02:46.730
They've got this great
configuration mechanism
00:02:46.730 --> 00:02:49.245
where you can layer
your configuration.
00:02:49.245 --> 00:02:52.355
You've got several different
configuration sources
00:02:52.355 --> 00:02:55.310
and you can pull
together the unity of
00:02:55.310 --> 00:02:58.750
those various
configurations settings
00:02:58.750 --> 00:03:01.420
and use that for
your application.
00:03:01.420 --> 00:03:04.865
With .NET Framework you
can't really do that.
00:03:04.865 --> 00:03:06.980
You have a app config
file or you have
00:03:06.980 --> 00:03:09.345
a Web config file that's
hanging out there.
00:03:09.345 --> 00:03:13.480
It's XML format and
unlike .NET Core,
00:03:13.480 --> 00:03:15.350
you can't really get
configuration from
00:03:15.350 --> 00:03:18.090
a third party source
in jam it into
00:03:18.090 --> 00:03:20.590
the configuration manager object
00:03:20.590 --> 00:03:26.460
without playing some games
with those config files.
00:03:26.460 --> 00:03:28.950
So, we wanted to make that
easier and particularly,
00:03:28.950 --> 00:03:31.100
we wanted to make it
easier for folks to
00:03:31.100 --> 00:03:33.560
inject things like
environment variables,
00:03:33.560 --> 00:03:36.085
so that when they
deploy their existing
00:03:36.085 --> 00:03:40.785
ASP.NET, .NET applications
into a Docker container,
00:03:40.785 --> 00:03:42.680
they can load up
environment variables,
00:03:42.680 --> 00:03:44.495
they get load up Docker settings
00:03:44.495 --> 00:03:45.980
or even pull settings out of
00:03:45.980 --> 00:03:48.365
an Azure Key Vault
and inject them
00:03:48.365 --> 00:03:52.090
in and replace any settings
that are sitting in there.
00:03:52.090 --> 00:03:54.035
Maybe your app settings section
00:03:54.035 --> 00:03:56.240
or your connection
string section,
00:03:56.240 --> 00:03:57.830
so that you've got
00:03:57.830 --> 00:04:00.180
one configuration
you're pushing around.
00:04:00.180 --> 00:04:01.965
Should make things a lot easier.
00:04:01.965 --> 00:04:05.395
>> That's sounds pretty good.
I remember a few years ago,
00:04:05.395 --> 00:04:07.230
I was working on
different products and
00:04:07.230 --> 00:04:09.350
we had a similar concern
00:04:09.350 --> 00:04:11.150
where we had
configurations that were
00:04:11.150 --> 00:04:13.290
in various XML files,
00:04:13.290 --> 00:04:15.155
and some of them were in
databases, and whatnot.
00:04:15.155 --> 00:04:17.580
We had to create these classes of
00:04:17.580 --> 00:04:20.680
these libraries to aggregate
some of that stuff together.
00:04:20.680 --> 00:04:23.240
So, it's good to hear that
we're going to get support for
00:04:23.240 --> 00:04:24.445
some of those type of scenarios
00:04:24.445 --> 00:04:26.115
that's just out of the box now.
00:04:26.115 --> 00:04:28.575
>> Yeah. In fact, out of the box,
00:04:28.575 --> 00:04:31.580
we didn't define
a specific provider
00:04:31.580 --> 00:04:34.520
for these third party
configuration settings.
00:04:34.520 --> 00:04:36.670
We actually only
deliver with the .NET
00:04:36.670 --> 00:04:39.030
Framework, an abstract interface.
00:04:39.030 --> 00:04:43.210
We allow other folks to
build providers as needed,
00:04:43.210 --> 00:04:45.625
that they can add into
your application.
00:04:45.625 --> 00:04:47.740
Well, you can add into
your applications
00:04:47.740 --> 00:04:50.060
to enhance as you need be.
00:04:50.060 --> 00:04:52.280
So, by default, we made a couple
00:04:52.280 --> 00:04:55.165
of NuGet packages available
along with source code,
00:04:55.165 --> 00:04:58.605
to do environment
variables, Azure Key Vault,
00:04:58.605 --> 00:05:00.130
JSON files,
00:05:00.130 --> 00:05:03.110
and even a user secrets XML file
00:05:03.110 --> 00:05:05.040
that we can hide
elsewhere on disk,
00:05:05.040 --> 00:05:06.860
just like the user
secrets feature
00:05:06.860 --> 00:05:08.975
that we have in ASP.NET Core.
00:05:08.975 --> 00:05:09.570
>> Cool.
00:05:09.570 --> 00:05:11.520
So, you have any demos that
we can take a look at?
00:05:11.520 --> 00:05:14.025
>> Oh, absolutely,
have I got demos.
00:05:14.025 --> 00:05:15.280
>> Let's get to it.
00:05:15.280 --> 00:05:16.120
>> All right.
00:05:16.120 --> 00:05:18.765
>> You mentioned that this
feature is available.
00:05:18.765 --> 00:05:22.155
This particular feature is
available in 4.7.1, correct?
00:05:22.155 --> 00:05:25.685
>> This feature is available
in .NET 4.7.1 and later.
00:05:25.685 --> 00:05:26.030
>> Okay.
00:05:26.030 --> 00:05:29.690
>> So, you can update your
application to .NET Framework
00:05:29.690 --> 00:05:32.160
4.7.1 and you can get access to
00:05:32.160 --> 00:05:34.995
this without changing
any of your code.
00:05:34.995 --> 00:05:37.920
This is strictly
a configuration file change
00:05:37.920 --> 00:05:41.165
once you do that
rebuild with 4.7.1.
00:05:41.165 --> 00:05:41.780
>> Got it.
00:05:41.780 --> 00:05:43.650
>> So, there are several
00:05:43.650 --> 00:05:45.510
configuration builders
like I mentioned out
00:05:45.510 --> 00:05:49.575
there available on nuget.org
that you can download.
00:05:49.575 --> 00:05:51.480
I want to show you
two of them here.
00:05:51.480 --> 00:05:54.080
The first one is the
environment variable,
00:05:54.080 --> 00:05:55.850
configuration builder.
00:05:55.850 --> 00:05:59.920
If I take a look at my
NuGet packages here,
00:05:59.920 --> 00:06:02.685
let's look at the installed ones
00:06:02.685 --> 00:06:05.070
named configuration builders.
00:06:05.070 --> 00:06:06.475
You can see I have
00:06:06.475 --> 00:06:08.235
Microsoft Configuration
00:06:08.235 --> 00:06:10.305
configuration builders
environment
00:06:10.305 --> 00:06:11.940
installed and I also have
00:06:11.940 --> 00:06:14.700
Microsoft Configuration
configuration builders
00:06:14.700 --> 00:06:16.340
Azure installed.
00:06:16.340 --> 00:06:18.780
When I install those,
00:06:18.780 --> 00:06:21.360
it automatically adds a section,
00:06:21.360 --> 00:06:23.525
definition to
your Web config file.
00:06:23.525 --> 00:06:26.400
It will also do that for
your app config file as well,
00:06:26.400 --> 00:06:29.040
and it will add a
configuration builder section
00:06:29.040 --> 00:06:30.600
here where we define
00:06:30.600 --> 00:06:33.210
which configuration builders
we want to load up and
00:06:33.210 --> 00:06:36.375
have access to in
our application.
00:06:36.375 --> 00:06:39.540
Now, before I actually use these,
00:06:39.540 --> 00:06:41.460
let me just show
you the demo page
00:06:41.460 --> 00:06:45.555
to evaluate and show
you what's presented.
00:06:45.555 --> 00:06:47.130
I have a default ASPX in
00:06:47.130 --> 00:06:49.155
this sample project
that just does a
00:06:49.155 --> 00:06:53.060
four each through configuration
manager app settings,
00:06:53.060 --> 00:06:56.100
all keys, and outputs the key,
00:06:56.100 --> 00:06:57.540
and then the value that it finds
00:06:57.540 --> 00:06:59.250
inside of configuration manager.
00:06:59.250 --> 00:07:02.780
So, this is a standard
API that we've had
00:07:02.780 --> 00:07:05.190
since .NET Framework 1 to
00:07:05.190 --> 00:07:07.570
be able to work with
our configuration.
00:07:07.570 --> 00:07:12.820
But, if I have these
app settings by default here,
00:07:12.820 --> 00:07:15.160
some service that I
want to connect out to,
00:07:15.160 --> 00:07:18.070
and some secret value
as my service key.
00:07:18.070 --> 00:07:21.665
I can start to reference
my environment,
00:07:21.665 --> 00:07:24.070
configuration builder
by adding this
00:07:24.070 --> 00:07:28.520
attributes to the element
that I want to work with.
00:07:28.940 --> 00:07:33.130
So, I specified we're going
to modify this section with
00:07:33.130 --> 00:07:35.740
config builders and then
I give it the name of
00:07:35.740 --> 00:07:39.430
the config builder that
I want to apply to it.
00:07:39.430 --> 00:07:42.020
>> So, quick question
about that part.
00:07:42.020 --> 00:07:44.370
So, on line 15,
00:07:44.370 --> 00:07:45.420
I'm looking at app settings,
00:07:45.420 --> 00:07:47.480
and then there's a property
called Config Builders,
00:07:47.480 --> 00:07:49.195
you set it to some value.
00:07:49.195 --> 00:07:50.950
Can I have multiple
00:07:50.950 --> 00:07:53.140
configuration builders
in that property?
00:07:53.140 --> 00:07:56.485
>> Oh, yes. You can
comma delimit these
00:07:56.485 --> 00:08:01.320
and it will chain together
from left to right.
00:08:01.320 --> 00:08:05.050
The various values adding on in
00:08:05.050 --> 00:08:07.345
just the same way that
you do in ASP.NET
00:08:07.345 --> 00:08:10.045
Core where it last one and wins.
00:08:10.045 --> 00:08:10.835
>> Nice.
00:08:10.835 --> 00:08:14.985
>> So. Oh, yes. So, let's
let's start with this.
00:08:14.985 --> 00:08:18.250
So, I have these two settings
here in my project.
00:08:18.250 --> 00:08:20.955
If I didn't specify
a config builders argument here,
00:08:20.955 --> 00:08:23.105
these values would be
output to the screen.
00:08:23.105 --> 00:08:25.600
Let's just start this and
00:08:25.600 --> 00:08:28.490
we should see two different
values pop up for
00:08:28.490 --> 00:08:31.690
my service ID and service
key coming out of
00:08:31.690 --> 00:08:35.945
environment [inaudible]
on my machine here.
00:08:35.945 --> 00:08:39.450
There you go. Fritz desktop and
00:08:39.450 --> 00:08:41.700
then really secret key hiding
00:08:41.700 --> 00:08:44.845
in an environment variable
so that no one can see it.
00:08:44.845 --> 00:08:47.670
They've been loaded and I
00:08:47.670 --> 00:08:49.800
didn't have to make
any changes, right?
00:08:49.800 --> 00:08:51.060
>> Nice.
00:08:51.060 --> 00:08:53.530
>> Then, the second one
that I wanted to show
00:08:53.530 --> 00:08:55.585
is the Azure Key Vault feature.
00:08:55.585 --> 00:08:59.935
So, we have Azure Key Vault
that we can specify.
00:08:59.935 --> 00:09:02.910
I specified the name
of my Azure Key Vault
00:09:02.910 --> 00:09:06.905
that's running out there in
my Azure Active Directory.
00:09:06.905 --> 00:09:09.620
It's configured with a couple
of settings and because
00:09:09.620 --> 00:09:12.695
I'm logged into Visual Studio
as you can see up here,
00:09:12.695 --> 00:09:16.975
it will use those credentials
to connect out to Azure and
00:09:16.975 --> 00:09:19.100
access my Key Vault that has
00:09:19.100 --> 00:09:22.015
this name and fetch
values from it.
00:09:22.015 --> 00:09:23.890
>> Now, this one
looks a little bit
00:09:23.890 --> 00:09:25.470
different from
the previous one, right?
00:09:25.470 --> 00:09:27.640
So, this one now is taking
some properties, right?
00:09:27.640 --> 00:09:29.750
It's taking a vault
name and a mode.
00:09:29.750 --> 00:09:34.385
So, I'm guessing as the
configuration builders created,
00:09:34.385 --> 00:09:36.100
that you can specify, "Hey,
00:09:36.100 --> 00:09:39.200
I can add some of these
extra values and it would go
00:09:39.200 --> 00:09:40.460
in there to configure
00:09:40.460 --> 00:09:42.710
your configuration
builders so to speak."
00:09:42.710 --> 00:09:44.340
>> Absolutely. So, if I had
00:09:44.340 --> 00:09:46.210
a JSON file that
I wanted to load,
00:09:46.210 --> 00:09:48.340
I could specify that filename
00:09:48.340 --> 00:09:51.640
in the definition of
the config builder here.
00:09:51.640 --> 00:09:55.995
That way, I could load
several different JSON files
00:09:55.995 --> 00:09:58.070
as different builder entries
00:09:58.070 --> 00:10:00.555
here with the exact same syntax.
00:10:00.555 --> 00:10:02.080
But, in this case, I'm passing
00:10:02.080 --> 00:10:03.510
properties of the vault name to
00:10:03.510 --> 00:10:06.990
connect to and this Greedy mode.
00:10:06.990 --> 00:10:09.250
This mode is actually a feature
00:10:09.250 --> 00:10:11.090
that many of our
configuration builders
00:10:11.090 --> 00:10:15.095
have where we can
say make it strict,
00:10:15.095 --> 00:10:17.590
where it will only
bring down values that
00:10:17.590 --> 00:10:20.805
match the properties that
we're trying to replace,
00:10:20.805 --> 00:10:22.850
or I can say Greedy which will
00:10:22.850 --> 00:10:25.010
go and get all of
the values that are
00:10:25.010 --> 00:10:27.750
available out there and make
00:10:27.750 --> 00:10:31.320
those additional keys
inside of my app settings.
00:10:31.320 --> 00:10:33.330
So, that's what I'm doing
here is I'm going to
00:10:33.330 --> 00:10:35.000
say "Go get all of the settings
00:10:35.000 --> 00:10:37.200
that are available and
let's add them and
00:10:37.200 --> 00:10:40.280
create new keys inside
of my app settings."
00:10:40.280 --> 00:10:40.985
>> Got it.
00:10:40.985 --> 00:10:46.345
>> So, I can switch to my Azure
Key Vault just by making,
00:10:46.345 --> 00:10:50.250
not that change. That change.
00:10:50.250 --> 00:10:54.365
Don't place it into
the comment. All right.
00:10:54.365 --> 00:10:56.255
So, if I start now,
00:10:56.255 --> 00:10:58.640
it'll use like I said the
credentials that I use to log
00:10:58.640 --> 00:11:01.365
into Visual Studio to
00:11:01.365 --> 00:11:04.750
authenticate and bring
back my data for
00:11:04.750 --> 00:11:06.640
all of the keys that
are defined inside of
00:11:06.640 --> 00:11:09.720
the Key Vault that I
called "Summit demo".
00:11:09.990 --> 00:11:12.770
There you go. So, I
have the same service
00:11:12.770 --> 00:11:14.145
ID and service key,
00:11:14.145 --> 00:11:17.660
but a Greedy connected
my GitHub password
00:11:17.660 --> 00:11:20.100
and some other
configuration information
00:11:20.100 --> 00:11:22.265
that's stored out
there in my Key Vault.
00:11:22.265 --> 00:11:22.555
>> Right.
00:11:22.555 --> 00:11:24.130
>> Now, I might not use this in
00:11:24.130 --> 00:11:27.560
my application but that's
the purpose of Greedy,
00:11:27.560 --> 00:11:29.260
is we'll bring everything
back and we'll
00:11:29.260 --> 00:11:31.905
figure out what to
do with it later.
00:11:31.905 --> 00:11:35.560
>> That's pretty cool. So,
I like how easy it is.
00:11:35.560 --> 00:11:37.480
It goes from, hey,
00:11:37.480 --> 00:11:39.620
let's take some
local configuration
00:11:39.620 --> 00:11:41.330
from my Web config file,
00:11:41.330 --> 00:11:43.300
then I can easily switch
it to be like, hey, well,
00:11:43.300 --> 00:11:44.660
let's also include some stuff
00:11:44.660 --> 00:11:45.910
from an environment variable.
00:11:45.910 --> 00:11:48.820
No, it's not in my product,
but it's on the machine.
00:11:48.820 --> 00:11:50.660
Then, you went even
further now, right?
00:11:50.660 --> 00:11:52.190
You took it up to
another level and
00:11:52.190 --> 00:11:53.855
you took it all the way
up to Azure Key Vault,
00:11:53.855 --> 00:11:57.200
which is like our
secure storage facility
00:11:57.200 --> 00:11:59.200
for some of these
applications secrets,
00:11:59.200 --> 00:12:00.570
and keys, and what not.
00:12:00.570 --> 00:12:03.660
>> Absolutely. If you deploy
00:12:03.660 --> 00:12:07.440
your application then to app
service running in Azure.
00:12:07.440 --> 00:12:10.970
Well if your app service
application is authorized as
00:12:10.970 --> 00:12:14.020
an application in
your active directory
00:12:14.020 --> 00:12:15.995
with access to the key vault,
00:12:15.995 --> 00:12:18.260
it will be able to
do the log in and
00:12:18.260 --> 00:12:21.760
automatically pull down
those values as well.
00:12:21.760 --> 00:12:23.805
So, zero configuration.
00:12:23.805 --> 00:12:31.120
No secrets get saved to
disk on your app server.
00:12:31.120 --> 00:12:33.880
It's just the name of
the vault to connect to.
00:12:33.880 --> 00:12:35.865
>> I think that's very
important particularly
00:12:35.865 --> 00:12:38.030
for resource control purposes.
00:12:38.030 --> 00:12:39.390
I don't want to have to check in
00:12:39.390 --> 00:12:41.600
my secrets into source control,
00:12:41.600 --> 00:12:43.950
but now I can set up
these configuration providers
00:12:43.950 --> 00:12:45.220
and then instead I can get
00:12:45.220 --> 00:12:46.690
those values from somewhere else.
00:12:46.690 --> 00:12:48.120
I don't have to worry about
00:12:48.120 --> 00:12:49.810
sensitive information
being stored
00:12:49.810 --> 00:12:52.200
unlike my source control history.
00:12:52.200 --> 00:12:55.020
>> Absolutely. Saved
on disk somewhere on
00:12:55.020 --> 00:12:57.835
a machine that's been
decommissioned and somebody finds.
00:12:57.835 --> 00:13:00.615
Yeah. It's completely out
00:13:00.615 --> 00:13:05.515
of any control that you
might have on it, right?
00:13:05.515 --> 00:13:07.755
We're only accessing
what we need.
00:13:07.755 --> 00:13:09.790
>> Nice. I really
liked this feature.
00:13:09.790 --> 00:13:11.390
You have another feature too
00:13:11.390 --> 00:13:12.970
that you wanted to talk
to us about, right?
00:13:12.970 --> 00:13:16.240
>> Yes. So, that other
feature that we just
00:13:16.240 --> 00:13:20.975
recently added is
dependency injection.
00:13:20.975 --> 00:13:23.550
>> So, what is
dependency injection for all
00:13:23.550 --> 00:13:26.010
of us who might not know
what that is exactly.
00:13:26.010 --> 00:13:30.355
>> So, dependency injection
is the capability of
00:13:30.355 --> 00:13:35.660
our applications of our classes
to have passed to them,
00:13:35.660 --> 00:13:38.360
passed and typically
through a constructor,
00:13:38.360 --> 00:13:40.690
the objects that
they need in order
00:13:40.690 --> 00:13:44.355
to provide business value.
00:13:44.355 --> 00:13:44.805
>> Yeah.
00:13:44.805 --> 00:13:46.365
>> So, for example,
00:13:46.365 --> 00:13:48.115
I have a page here.
00:13:48.115 --> 00:13:51.560
This is a normal
system Web UI page
00:13:51.560 --> 00:13:55.630
that has a product
repository class on it.
00:13:55.630 --> 00:13:59.745
It's starting up, it's creating
a new product repository,
00:13:59.745 --> 00:14:01.000
and then I'm using model
00:14:01.000 --> 00:14:02.890
binding in this method
here on lines
00:14:02.890 --> 00:14:06.180
22-25 to fetch data.
00:14:06.180 --> 00:14:09.610
Fetch a list of products
from that repository as
00:14:09.610 --> 00:14:12.230
a queryable object that the page
00:14:12.230 --> 00:14:15.695
itself will use as
part of a grid view,
00:14:15.695 --> 00:14:19.755
right there in the select method
to populate the grid.
00:14:19.755 --> 00:14:21.570
>> Wow, so we have MDIN
00:14:21.570 --> 00:14:23.775
model binding available
now in Web Forms.
00:14:23.775 --> 00:14:29.305
>> Model binding's been
around since ASP.NET 4.5.
00:14:29.305 --> 00:14:32.445
So, yes model binding
is very much available.
00:14:32.445 --> 00:14:35.055
All of our data bound controls
00:14:35.055 --> 00:14:37.810
have these method attributes,
00:14:37.810 --> 00:14:39.540
all of them like, select method,
00:14:39.540 --> 00:14:41.490
insert method, update method,
00:14:41.490 --> 00:14:45.660
and delete method, that
are pointers in our ASPX
00:14:45.660 --> 00:14:51.985
files back to a method here
inside of our code behind.
00:14:51.985 --> 00:14:54.510
>> Right. So, now with
dependency injection.
00:14:54.510 --> 00:14:56.650
That's something very
common that we see a lot
00:14:56.650 --> 00:14:58.619
with our MVC applications
00:14:58.619 --> 00:15:00.850
where ASP.NET Core applications.
00:15:00.850 --> 00:15:02.795
To the point that
it's actually baked
00:15:02.795 --> 00:15:04.555
in and it's a part of
the core framework.
00:15:04.555 --> 00:15:05.710
So, it's really
good to see some of
00:15:05.710 --> 00:15:07.830
these features that are
coming into Web Forms.
00:15:07.830 --> 00:15:10.705
>> Right. Absolutely. This is
00:15:10.705 --> 00:15:12.960
another one of
those features that's
00:15:12.960 --> 00:15:15.400
helping to give you
00:15:15.400 --> 00:15:18.410
the ability to do
some refactoring now.
00:15:18.410 --> 00:15:22.325
Push things like
your database access layer,
00:15:22.325 --> 00:15:25.050
out into a separate
class library.
00:15:25.050 --> 00:15:29.330
Have it injected at run time,
00:15:29.330 --> 00:15:32.300
so that it's outside of
the Web Forms project,
00:15:32.300 --> 00:15:33.950
and you can start
to move that into
00:15:33.950 --> 00:15:36.535
perhaps a .NET standard
class library,
00:15:36.535 --> 00:15:40.270
where when you do your
.NET Core rewrite,
00:15:40.270 --> 00:15:42.355
you can reuse that code.
00:15:42.355 --> 00:15:45.070
>> Nice. Well let's
stop talking about it.
00:15:45.070 --> 00:15:46.460
Let me see how this work.
00:15:46.460 --> 00:15:51.365
>> Right. So, I'm doing
that product repository here.
00:15:51.365 --> 00:15:53.500
But, really what I want to do is
00:15:53.500 --> 00:15:55.645
pass that in on a constructor.
00:15:55.645 --> 00:15:58.300
So, I'll use the C tor snippet
00:15:58.300 --> 00:16:00.630
to generate my constructor here.
00:16:00.630 --> 00:16:03.560
My product repository implements
00:16:03.560 --> 00:16:05.945
the I-product
repository interface,
00:16:05.945 --> 00:16:08.235
and it returns just a pair of
00:16:08.235 --> 00:16:09.770
nonsense product objects that
00:16:09.770 --> 00:16:11.920
return the names foo and bar.
00:16:11.920 --> 00:16:15.370
So, let's bring in
an I-product repository.
00:16:15.370 --> 00:16:22.140
Here, I-product repository
and I'll just call it repo.
00:16:22.140 --> 00:16:27.430
I'll specify that,
this repository is
00:16:27.430 --> 00:16:30.170
that repository class that
was passed in and I can
00:16:30.170 --> 00:16:33.740
get rid of this
initialization here.
00:16:33.740 --> 00:16:37.430
The phrase new is glue
is something that
00:16:37.430 --> 00:16:40.910
we're familiar with whereby
putting a new here,
00:16:40.910 --> 00:16:43.030
we're tying
that implementation of
00:16:43.030 --> 00:16:45.690
a product repository
to this class.
00:16:45.690 --> 00:16:47.900
So, this changes things to make
00:16:47.900 --> 00:16:50.890
it a little bit more
loosely coupled.
00:16:50.890 --> 00:16:55.215
The last piece of this
is we actually need to
00:16:55.215 --> 00:16:58.370
connect this product
repository object
00:16:58.370 --> 00:17:00.965
to a dependency
injection container.
00:17:00.965 --> 00:17:03.780
So, it knows how to turn
00:17:03.780 --> 00:17:06.940
this request for an eye product
repository interface into
00:17:06.940 --> 00:17:10.190
a concrete product
repository and I have
00:17:10.190 --> 00:17:13.990
that over here in my
Unity config class.
00:17:13.990 --> 00:17:15.870
So, I have a simple
configure method
00:17:15.870 --> 00:17:18.835
here that creates
a new Unity container and
00:17:18.835 --> 00:17:21.875
it registers the type
eye product repository
00:17:21.875 --> 00:17:24.705
should deliver
a product repository.
00:17:24.705 --> 00:17:29.435
That's garden variety, Unity
container configuration,
00:17:29.435 --> 00:17:32.235
but this is the glue here.
00:17:32.235 --> 00:17:36.190
The web object activator
is a new Unity config.
00:17:36.190 --> 00:17:38.280
It's a new one of these things.
00:17:38.280 --> 00:17:41.345
Now, "Web Object Activator" is
00:17:41.345 --> 00:17:44.230
an eye service provider that
you need to implement if
00:17:44.230 --> 00:17:47.380
you're going to go all the
way down and create one of
00:17:47.380 --> 00:17:49.275
these classes for
00:17:49.275 --> 00:17:52.810
your favorite dependency
injection container.
00:17:52.810 --> 00:17:55.235
The one method you need
to implement is get
00:17:55.235 --> 00:17:58.810
service for a given type
returns or map object.
00:17:58.810 --> 00:18:01.410
So, all we're doing
is saying look at
00:18:01.410 --> 00:18:04.390
that surface type that's
requested which will
00:18:04.390 --> 00:18:07.970
be this page and
00:18:07.970 --> 00:18:09.470
then we're going to go down and
00:18:09.470 --> 00:18:11.745
say look at the constructors.
00:18:11.745 --> 00:18:15.285
If the constructor
has parameters where
00:18:15.285 --> 00:18:16.660
all the parameter types are
00:18:16.660 --> 00:18:19.500
registered node
container, resolve.
00:18:19.500 --> 00:18:22.470
Container go build me
up one of those things,
00:18:22.470 --> 00:18:24.470
in this case, my default page.
00:18:24.470 --> 00:18:26.630
If we can't do that,
00:18:26.630 --> 00:18:29.420
then we're just going to
do a standard activator
00:18:29.420 --> 00:18:32.610
create instance of that object.
00:18:32.610 --> 00:18:36.165
Now what's great about
this is I'm not coupled
00:18:36.165 --> 00:18:39.735
to just a system web UI page.
00:18:39.735 --> 00:18:42.250
This also works for user controls
00:18:42.250 --> 00:18:45.385
and other custom controls
inside your application.
00:18:45.385 --> 00:18:48.190
>> Got it. Does
that also work for
00:18:48.190 --> 00:18:49.450
handlers and modules per
00:18:49.450 --> 00:18:51.615
se if I wanted to
do this in-house?
00:18:51.615 --> 00:18:56.875
>> Absolutely. It will
work for A-S-H-X files,
00:18:56.875 --> 00:19:00.640
it'll work for ASMX files,
your soap services.
00:19:00.640 --> 00:19:06.890
So you have a simple
implementation
00:19:06.890 --> 00:19:08.230
that works really across
00:19:08.230 --> 00:19:11.670
the entire system
web-based framework.
00:19:11.670 --> 00:19:14.335
This doesn't work
with MVC where you're
00:19:14.335 --> 00:19:17.270
building up controllers
there or web API that,
00:19:17.270 --> 00:19:19.915
there's a separate configuration
for those things,
00:19:19.915 --> 00:19:22.260
but this will get you in with
00:19:22.260 --> 00:19:25.070
that base level of
system web capabilities.
00:19:25.070 --> 00:19:26.015
>> Nice.
00:19:26.015 --> 00:19:28.930
>> So, let's fire it up and
just show that it does,
00:19:28.930 --> 00:19:31.920
in fact, return our object.
00:19:32.680 --> 00:19:35.305
>> So whatever you like
while that's booting up,
00:19:35.305 --> 00:19:38.160
what I really like about this
is so to just register it,
00:19:38.160 --> 00:19:39.730
all you need to do
is just assign it to
00:19:39.730 --> 00:19:43.400
that web object activator
and then the system would
00:19:43.400 --> 00:19:45.095
just automatically pick
it up like I don't have
00:19:45.095 --> 00:19:46.885
a separate thing I have to do in
00:19:46.885 --> 00:19:48.890
global.asax or
anything like that.
00:19:48.890 --> 00:19:51.020
It could just kind of
happened in that space.
00:19:51.020 --> 00:19:53.355
>> It just happens.
We load up and I got
00:19:53.355 --> 00:19:55.730
my two products
coming back inside
00:19:55.730 --> 00:19:58.490
of a very simple grid
on the default page.
00:19:58.490 --> 00:20:00.785
So right.
00:20:00.785 --> 00:20:04.545
The idea here is to make
that rearchitecting
00:20:04.545 --> 00:20:06.560
that many of our customers
00:20:06.560 --> 00:20:08.210
want to do of their applications,
00:20:08.210 --> 00:20:11.060
so they can consider a .NET core,
00:20:11.060 --> 00:20:12.995
a .NET standard class library.
00:20:12.995 --> 00:20:16.760
Make that easier to
do by allowing you to
00:20:16.760 --> 00:20:19.115
refactor and take advantage
00:20:19.115 --> 00:20:22.350
of modern dependency
injection capabilities.
00:20:22.350 --> 00:20:25.470
>> Nice. So, if I wanted to
learn a little bit more about
00:20:25.470 --> 00:20:26.990
this feature and also even
00:20:26.990 --> 00:20:28.875
the configuration
build us feature,
00:20:28.875 --> 00:20:30.255
where can I go to get
00:20:30.255 --> 00:20:31.570
some reference materials maybe
00:20:31.570 --> 00:20:33.100
even see some samples about it?
00:20:33.100 --> 00:20:37.120
>> Sure. Let me go to,
00:20:37.120 --> 00:20:43.195
I have a blog post here
on the ASP.NET blog.
00:20:43.195 --> 00:20:46.795
If you go to
blogsMSDN.com/webdev.
00:20:46.795 --> 00:20:48.535
This is called Use Dependency
00:20:48.535 --> 00:20:51.180
Injection in
a WebForms Application.
00:20:51.180 --> 00:20:52.440
Go ahead and check this out and
00:20:52.440 --> 00:20:53.530
there's another sample here
00:20:53.530 --> 00:20:55.650
that you can see
that shows you how
00:20:55.650 --> 00:20:59.325
to upgrade to .NET
Framework 472 and apply
00:20:59.325 --> 00:21:02.355
these changes and take
00:21:02.355 --> 00:21:04.965
advantage of dependency
injection with Unity.
00:21:04.965 --> 00:21:07.860
For configuration builders,
there's an entry in
00:21:07.860 --> 00:21:11.305
the docs at docsmicrosoft.com.
00:21:11.305 --> 00:21:14.740
If you look up the
configuration builder class,
00:21:14.740 --> 00:21:16.855
there's a complete article
here about how to
00:21:16.855 --> 00:21:19.300
write your own
configuration builder,
00:21:19.300 --> 00:21:23.085
as well as, how to
do the configuration
00:21:23.085 --> 00:21:27.520
inside of your web config
or app config class, file.
00:21:27.520 --> 00:21:29.110
And then links to
00:21:29.110 --> 00:21:31.305
our existing
configuration builders
00:21:31.305 --> 00:21:34.635
that are available
for you on NuGet.
00:21:34.635 --> 00:21:36.530
>> Just like the dependency
00:21:36.530 --> 00:21:37.890
injection stuff
like both of these
00:21:37.890 --> 00:21:39.045
should be pretty easy to
00:21:39.045 --> 00:21:41.080
create my own if I
wanted to, right?
00:21:41.080 --> 00:21:44.345
>> Absolutely. I've taken
some time and I've built
00:21:44.345 --> 00:21:46.410
my own configuration
builders to read
00:21:46.410 --> 00:21:48.615
from things like
an INI file, right?
00:21:48.615 --> 00:21:50.720
Those INI files that people
00:21:50.720 --> 00:21:52.840
loved so much before Windows 95.
00:21:52.840 --> 00:21:55.160
There's still a bunch of
them out there and people
00:21:55.160 --> 00:21:57.790
like to be able to read
from those as well.
00:21:57.790 --> 00:21:59.450
So that's one option.
00:21:59.450 --> 00:22:00.640
I even wrote one to read from
00:22:00.640 --> 00:22:04.380
an RSS endpoint. So
you could publish.
00:22:04.380 --> 00:22:07.055
Here's the configuration
that I want on a web server
00:22:07.055 --> 00:22:09.700
somewhere as an RSS file
and be able to
00:22:09.700 --> 00:22:12.740
read that in and configure
your application
00:22:12.740 --> 00:22:16.945
from a central location like
that off server entirely.
00:22:16.945 --> 00:22:18.700
So pretty interesting.
00:22:18.700 --> 00:22:21.835
>> So, if I have an existing
Windows forms application
00:22:21.835 --> 00:22:24.605
and I upgrade to 4.7.1,
00:22:24.605 --> 00:22:26.260
do I have to do anything special,
00:22:26.260 --> 00:22:26.775
do I have to pull in
00:22:26.775 --> 00:22:28.570
any packages or should
these features just
00:22:28.570 --> 00:22:31.630
light up and be available for me?
00:22:31.630 --> 00:22:34.470
>> If you upgrade to
471 with Windows Forms,
00:22:34.470 --> 00:22:38.295
you will need to update,
00:22:38.295 --> 00:22:40.810
to install those packages for
00:22:40.810 --> 00:22:44.115
configuration builders and
update your config file.
00:22:44.115 --> 00:22:46.650
Now, installing those packages
00:22:46.650 --> 00:22:48.610
doesn't mean you
need to recompile,
00:22:48.610 --> 00:22:50.470
you just need to
get the DLLs into
00:22:50.470 --> 00:22:53.045
the bin folder with your project.
00:22:53.045 --> 00:22:57.460
We'll use reflection to
load up those capabilities,
00:22:57.460 --> 00:22:59.620
write the application startup and
00:22:59.620 --> 00:23:02.255
apply that configuration
to your application.
00:23:02.255 --> 00:23:04.315
>> Cool. Well, this is
awesome and thank you so
00:23:04.315 --> 00:23:05.080
much for coming on and
00:23:05.080 --> 00:23:06.710
talking to us about
this features yeah.
00:23:06.710 --> 00:23:08.140
>> Oh, thanks so
much for having me.
00:23:08.140 --> 00:23:09.340
I really appreciate the time
00:23:09.340 --> 00:23:12.110
to share these features
with folks that
00:23:12.110 --> 00:23:13.985
are interested in modernizing
00:23:13.985 --> 00:23:15.180
and taking advantage of some of
00:23:15.180 --> 00:23:18.180
these capabilities
that .NET framework
00:23:18.180 --> 00:23:19.855
hasn't had until recently.
00:23:19.855 --> 00:23:21.810
>> Yeah, this has
definitely been awesome.
00:23:21.810 --> 00:23:23.600
So this is another episode of the
00:23:23.600 --> 00:23:26.160
On .NET Show. Thank
you all for watching.