1
00:00:00,940 --> 00:00:02,850
You can download the sample application

2
00:00:02,850 --> 00:00:04,980
both in the course downloads or from the

3
00:00:04,980 --> 00:00:06,680
GitHub repository that you see on your

4
00:00:06,680 --> 00:00:09,370
screen. Within those downloads, you'll

5
00:00:09,370 --> 00:00:11,620
find a version of the sample code both for

6
00:00:11,620 --> 00:00:15,010
.NET Core and .NET Framework. In terms of

7
00:00:15,010 --> 00:00:16,860
implementing the decorator pattern, the

8
00:00:16,860 --> 00:00:18,890
code is the same, save for the part where

9
00:00:18,890 --> 00:00:20,270
you have to configure your decorator

10
00:00:20,270 --> 00:00:22,500
classes to work with an IoC Container,

11
00:00:22,500 --> 00:00:25,190
which we'll cover in a few clips. I'll be

12
00:00:25,190 --> 00:00:27,530
primarily using the .NET Core project in

13
00:00:27,530 --> 00:00:30,150
the demos, but again, the concepts in the

14
00:00:30,150 --> 00:00:32,120
code are the same regardless of what

15
00:00:32,120 --> 00:00:34,840
version of .NET that you're using.

16
00:00:34,840 --> 00:00:37,060
Switching over to the sample application,

17
00:00:37,060 --> 00:00:39,770
we see that we have an ASP.NET MVC web

18
00:00:39,770 --> 00:00:41,970
application that will serve as a container

19
00:00:41,970 --> 00:00:44,200
for the code that we write. And what this

20
00:00:44,200 --> 00:00:46,080
app does is it displays the current

21
00:00:46,080 --> 00:00:48,100
weather conditions for a location on the

22
00:00:48,100 --> 00:00:50,680
home page. By default, we're showing the

23
00:00:50,680 --> 00:00:53,420
weather for Chicago because I'm in

24
00:00:53,420 --> 00:00:54,840
Chicago, but you could also type in any

25
00:00:54,840 --> 00:00:56,990
city name in this box and the app will

26
00:00:56,990 --> 00:00:59,720
reach out and call the OpenWeatherMap API

27
00:00:59,720 --> 00:01:01,430
to get the current weather conditions for

28
00:01:01,430 --> 00:01:04,540
that city and display them on the page.

29
00:01:04,540 --> 00:01:06,520
You can also click on the Forecast link at

30
00:01:06,520 --> 00:01:08,310
the top of this page, and that will

31
00:01:08,310 --> 00:01:09,820
exercise the other method in our

32
00:01:09,820 --> 00:01:11,610
WeatherService class and give you the

33
00:01:11,610 --> 00:01:15,300
forecast for whatever city you type in. If

34
00:01:15,300 --> 00:01:17,070
we switch over to the source code, we'll

35
00:01:17,070 --> 00:01:19,440
see that both the Index and the Forecast

36
00:01:19,440 --> 00:01:21,570
action methods are implemented in the

37
00:01:21,570 --> 00:01:25,060
HomeController for the application. And it

38
00:01:25,060 --> 00:01:26,380
is in the constructor of the

39
00:01:26,380 --> 00:01:28,000
HomeController that we see that our

40
00:01:28,000 --> 00:01:30,060
WeatherService object is being created

41
00:01:30,060 --> 00:01:32,940
right now. And examining this code brings

42
00:01:32,940 --> 00:01:35,480
up an important point. If you want to be

43
00:01:35,480 --> 00:01:37,240
able to download this code and run it

44
00:01:37,240 --> 00:01:38,950
yourself and follow along during the

45
00:01:38,950 --> 00:01:40,940
course, which I highly recommend that you

46
00:01:40,940 --> 00:01:44,110
do, you're going to need to get an API key

47
00:01:44,110 --> 00:01:47,600
for the OpenWeatherMap API. Otherwise, all

48
00:01:47,600 --> 00:01:49,800
of these API calls are going to fail on

49
00:01:49,800 --> 00:01:54,020
you. To get an API key, go to this page:

50
00:01:54,020 --> 00:01:58,330
openweathermap.org/price, and you can sign

51
00:01:58,330 --> 00:02:00,950
up for a free account, and once you do,

52
00:02:00,950 --> 00:02:04,510
you'll be able to get an API key. Once you

53
00:02:04,510 --> 00:02:06,320
have that key, just add it into your

54
00:02:06,320 --> 00:02:10,150
appsettings.json file for ASP.NET Core or

55
00:02:10,150 --> 00:02:12,680
web.config file for .NET Framework, and

56
00:02:12,680 --> 00:02:15,630
then you'll be all set to go. As for the

57
00:02:15,630 --> 00:02:17,490
rest of the code, the IWeatherService

58
00:02:17,490 --> 00:02:19,560
interface is defined in this folder,

59
00:02:19,560 --> 00:02:22,190
WeatherInterface, and alongside it you can

60
00:02:22,190 --> 00:02:24,090
see I have some standardized classes

61
00:02:24,090 --> 00:02:25,410
representing the current weather

62
00:02:25,410 --> 00:02:26,970
conditions and the forecast for a

63
00:02:26,970 --> 00:02:29,970
location. So any concrete implementations

64
00:02:29,970 --> 00:02:31,900
of this interface would need to map their

65
00:02:31,900 --> 00:02:35,010
results to these standard classes. The

66
00:02:35,010 --> 00:02:36,810
actual concrete implementation of our

67
00:02:36,810 --> 00:02:38,920
WeatherService class is up here in the

68
00:02:38,920 --> 00:02:41,390
OpenWeatherMap folder. So we have two

69
00:02:41,390 --> 00:02:42,860
classes that represent the actual

70
00:02:42,860 --> 00:02:45,250
responses that are received from the

71
00:02:45,250 --> 00:02:46,790
OpenWeatherMap API, and then this

72
00:02:46,790 --> 00:02:48,960
WeatherService class is the class that

73
00:02:48,960 --> 00:02:51,350
implements the IWeatherService interface,

74
00:02:51,350 --> 00:02:52,780
and it's the one that actually makes the

75
00:02:52,780 --> 00:02:55,490
API calls out to that RESTful service and

76
00:02:55,490 --> 00:02:57,010
maps the results into our standard

77
00:02:57,010 --> 00:02:59,890
objects. So with our tour complete, let's

78
00:02:59,890 --> 00:03:04,000
go ahead and write our first decorator class.

